Re: [理工] [OS] race condition
因為題目敘述有三個process執行
所以可以分成下面這種情況來討論
P1 P2 P3
------------------------------
T1:x=y T2:x=y T3:x=y
T4:x=x+1 T5:x=x+1 T6:x=x+1
T7 :y=x T8 :y=x T9 :y=x
若要y=2
則依照下面的順序執行即可
T1 T4 T7 T2 T3 T5 T6 T8 T9
有錯請指證!
※ 引述《wsx02 ()》之銘言:
: shared y;
: begin
: local x;
: x = y;
: x = x+1;
: y = x;
: end
: if local variable x and shared variable y initially 0 and three copies of the
: process run concurrently. What is the possible values of y after three copies
: of the process terminate?
: y的可能值有2
: 請問是怎麼跑出來的?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.169.104.4
推
03/13 21:28, , 1F
03/13 21:28, 1F
→
03/13 21:29, , 2F
03/13 21:29, 2F
→
03/13 21:30, , 3F
03/13 21:30, 3F
噢 沒注意到是local 感謝指證!
※ 編輯: Fight5566 來自: 118.169.104.4 (03/13 21:34)