[理工] [OS] 99交大資聯OS第19題

看板Grad-ProbAsk作者 (妖精鄉騎士)時間13年前 (2011/01/17 18:56), 編輯推噓1(1024)
留言25則, 5人參與, 最新討論串1/2 (看更多)
19.Consider that a system scheduls three processes P1,P2,P3 using Round-robin with time quantum=2 units of time. These three processes arrive in the order P1,P2,P3, all ready at time 0. The three processes share a resource R, which is protected by a mutex lock. The first process P1 runs 3 units of time, block the resource R 3 units of time,unlocks this resource,and then runs 1 unit of time before it completes. Let this execution of P1 be denoted by {3,R(3),1}. The execution of the second process P2 and the third process P3 are denoted by {2,R(1),3} and {2,R(2),2}, respectively. Let waiting queues be FIFO. which one(s) of the following is(are) true? A. The total number of context switches is not less than 9. B. T2 has the longest turnaround time. C. Decreasing P1's execution time from {3,R(3),1} to {3,R(1),1} reduces P2's turnaround time. D. Increasing P1's execution time from {3,R(3),1} to {4,R(3),1} reduces P2's turnaround time. 答案給ACD 但我自己算是只有A對 @@ 原本: | P1 | P2 | P3 | P1 | P2 | P3 | P2 | P1 | time 0 2 4 5 6 7 8 9 11 12 13 ^^^ ^^^^^^^^^^^^^^^^ R(1) R(2) R(3) time4~5 P2執行R(1) time6~8 P3執行R(2) time8~11 P1執行R(3) (C)選項的結果和原本一樣,P2的turnaround time沒變 (D)選項: P2的turnaround time增加 | P1 | P2 | P3 | P1 | P2 | P3 | P2 | P1 | time 0 2 4 6 8 10 12 13 14 不知道我哪裡算錯.. 有高手可以幫我解答嗎... 感恩 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.34.133.127

01/17 19:35, , 1F
關鍵似乎在mutex lock上?
01/17 19:35, 1F

01/17 19:52, , 2F
我有注意到mutex,應該是一次只能1 process block的意思
01/17 19:52, 2F

01/17 20:05, , 3F
我覺得題目意思是lock被process佔用,還沒用完時就算時間到了
01/17 20:05, 3F

01/17 20:06, , 4F
被換成其他process也不能執行吧@@
01/17 20:06, 4F

01/17 20:06, , 5F
所以順序可能是P1 P2 P3 P1 P2(不能執行)P3(不能執行)...
01/17 20:06, 5F

01/17 20:34, , 6F
樓上的意思是某Pi blocks resource時 其他process此時
01/17 20:34, 6F

01/17 20:34, , 7F
就無法得到CPU嗎?
01/17 20:34, 7F

01/17 20:49, , 8F
應該是可以得到CPU 但是沒辦法得到那個resource 所以不能往
01/17 20:49, 8F

01/17 20:51, , 9F
下執行吧 要等到process釋放那個資源 其他process才能執行
01/17 20:51, 9F

01/17 21:01, , 10F
那我的算法跟你的一樣...不過不會沒辦法執行耶
01/17 21:01, 10F
※ 編輯: dacvidania 來自: 114.34.133.127 (01/17 21:06)

01/17 21:19, , 11F
還是我哪裡算錯...
01/17 21:19, 11F

01/17 22:29, , 12F
我一開始也用你的算法
01/17 22:29, 12F

01/17 22:29, , 13F
不過後來試另外個方法 我也不知道正不正確啦
01/17 22:29, 13F

01/17 22:30, , 14F
就 R(3)的意思應該是持有資源還是要用CPU去執行 
01/17 22:30, 14F

01/17 22:31, , 15F
所以P2執行完 他要等到下次拿到CPU才會佔用resource
01/17 22:31, 15F

01/17 22:31, , 16F
試一試結果是對的
01/17 22:31, 16F

01/17 22:32, , 17F
所以這題應該是考觀念 不能跟I/O混淆 他只是拿共享資料
01/17 22:32, 17F

01/17 22:33, , 18F
不是發出block
01/17 22:33, 18F

01/17 22:40, , 19F
了解了~~謝謝 不過那個resource題目也沒說是什麼...
01/17 22:40, 19F

01/17 22:42, , 20F
如果是印表機之類那就是IO了
01/17 22:42, 20F

01/17 22:44, , 21F
對= = 所以看到交大的排班先直接跳過寫下一題
01/17 22:44, 21F

01/17 22:44, , 22F
有時間再回來寫好了。。 
01/17 22:44, 22F

01/17 22:44, , 23F
總覺得他是故意要讓人家以為是IO...
01/17 22:44, 23F

01/17 22:46, , 24F
不過他其實有提到是lock的 so...還是細心!!跟英文好
01/17 22:46, 24F
※ 編輯: dacvidania 來自: 114.34.133.127 (01/17 23:18)

09/11 14:09, , 25F
試一試結果是對的 https://daxiv.com
09/11 14:09, 25F
文章代碼(AID): #1DD21rt- (Grad-ProbAsk)
文章代碼(AID): #1DD21rt- (Grad-ProbAsk)