Re: [理工] [OS]-政大

看板Grad-ProbAsk作者 (ming)時間14年前 (2010/03/04 10:03), 編輯推噓2(2011)
留言13則, 2人參與, 最新討論串2/2 (看更多)
※ ()引述《bigrat2 (MrEric)》之銘言: : Give the follwing variables and their initial values as follows: : X:integer,initial value is 0 : y:integer,initial value is 23 : m:general semaphore,initial value is 1 : m1:general semaphore,initial value is 0 : For each of the following program,list values possible for x when the : program terminates. Note that"cobegin P1||P2 ;coend" means P1 and P2 : are executed concurrently, and ":=" is the assignment operator. : (1)cobegin P(m1);x:=x+1;V(m) || P(m);x=y+1;V(m1) coend : (2)cobegin V(m1);x:=x+1;P(m) || V(m1);x:=y+1;P(m1); coend : 答案(1) 25 (2) 1,24 or 25 : 我想請問一下P(m1) V(m1) P(m) V(m)是什麼意思呢? : 另外(2)的結果是怎麼推算出來的 : 謝謝各位指教 (2)在V(m1)的時候不會進入死結麼?? 答案不太懂位什麼是1,24,25 抱歉學校PPT不方便選字.................指教指教囉 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.18.75.130

03/04 10:50, , 1F
(2)的semephore根本就沒有效果 因為P(m1)寫在前面
03/04 10:50, 1F

03/04 10:52, , 2F
所以就把他看成 x:=x+1;---1 x:=y+1;---2 輪流執行
03/04 10:52, 2F

03/04 10:59, , 3F
先1再2=>x=24 先2再1=>x=25
03/04 10:59, 3F

03/04 11:02, , 4F
嗯嗯謝謝 race condition 想在請教一下 怎麼知道他們是
03/04 11:02, 4F

03/04 11:02, , 5F
wait or signal阿 有其他書用這種方式定義?
03/04 11:02, 5F

03/04 11:06, , 6F
在1的時後x+1尚未assign 但2已經做完 則x=1
03/04 11:06, 6F

03/04 11:08, , 7F
wait()=P() ,signal()=V() 就這樣記吧
03/04 11:08, 7F

03/04 11:09, , 8F
剛剛第一行打錯 應該是: 因為V(m1)寫在前面
03/04 11:09, 8F

03/04 11:22, , 9F
若是題目只寫出 例如:X() Y() 可以判斷出他是signal
03/04 11:22, 9F

03/04 11:23, , 10F
或wait()麼?? 這題主要不會,其實是因為不懂V 跟P哪個
03/04 11:23, 10F

03/04 11:23, , 11F
是signal OR wait
03/04 11:23, 11F

03/04 11:25, , 12F
題目不會這麼寫,semephore就只有這兩種定義方式
03/04 11:25, 12F

03/04 11:27, , 13F
嗯嗯 非常謝謝喔
03/04 11:27, 13F
文章代碼(AID): #1BZnJ_QK (Grad-ProbAsk)
討論串 (同標題文章)
本文引述了以下文章的的內容:
理工
0
1
完整討論串 (本文為第 2 之 2 篇):
理工
0
1
文章代碼(AID): #1BZnJ_QK (Grad-ProbAsk)