作者Fight5566 (单戈示申)
看板Grad-ProbAsk
标题Re: [理工] [OS] race condition
时间Tue Mar 13 21:19:30 2012
因为题目叙述有三个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
1F:推 wsx02:x是local variable 我照这样的顺序出来y=1 可以请问细节吗? 03/13 21:28
2F:→ wsx02:我造出来了 03/13 21:29
3F:→ wsx02:顺序是T1 T2 T4 T5 T7 T8 T3 T6 T9 谢谢 03/13 21:30
噢 没注意到是local 感谢指证!
※ 编辑: Fight5566 来自: 118.169.104.4 (03/13 21:34)