作者abc73021 (ming)
看板Grad-ProbAsk
標題Re: [理工] [OS]-政大
時間Thu Mar 4 10:03:41 2010
※ ()引述《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
推 lightergogo:(2)的semephore根本就沒有效果 因為P(m1)寫在前面 03/04 10:50
→ lightergogo:所以就把他看成 x:=x+1;---1 x:=y+1;---2 輪流執行 03/04 10:52
→ lightergogo:先1再2=>x=24 先2再1=>x=25 03/04 10:59
→ abc73021:嗯嗯謝謝 race condition 想在請教一下 怎麼知道他們是 03/04 11:02
→ abc73021:wait or signal阿 有其他書用這種方式定義? 03/04 11:02
→ lightergogo:在1的時後x+1尚未assign 但2已經做完 則x=1 03/04 11:06
→ lightergogo:wait()=P() ,signal()=V() 就這樣記吧 03/04 11:08
→ lightergogo:剛剛第一行打錯 應該是: 因為V(m1)寫在前面 03/04 11:09
→ abc73021:若是題目只寫出 例如:X() Y() 可以判斷出他是signal 03/04 11:22
→ abc73021:或wait()麼?? 這題主要不會,其實是因為不懂V 跟P哪個 03/04 11:23
→ abc73021:是signal OR wait 03/04 11:23
推 lightergogo:題目不會這麼寫,semephore就只有這兩種定義方式 03/04 11:25
→ abc73021:嗯嗯 非常謝謝喔 03/04 11:27