Sunday, February 1, 2009

Ch4, Ex1

    local B in
<S1> thread B=true end
<S2> thread B=false end
<S3> if B then {Browse yes} end
end

a) <S3> can complete only after either of <S1>, <S2> has been executed(or else it'll keep on waiting for B to bind.)
Possible orders:

Order1: <S1><S3><S2>
Order2: <S2><S3><S1>
In the end it'll fail as last stmt tries to rebind B, it can be checked by executing following
 local B in
thread B=true end
thread {Delay 500} B=false end
if B then {Browse yes} end
end

Order3: <S1><S2><S3>
Order4: <S2><S1><S3>
in both of these program fails after second statement execution it fails as it tries to bind B the second time, in fact <S3> is not even executed as can be checked by running following
local B in
thread B=true end
thread B=false end
thread {Delay 500} if B then {Browse yes}
else {Browse No} end end
end

b) I don't know what is the right answer but this one will never fail atleast
local B in
thread B=true end
if B then {Browse yes} end
end

No comments:

Post a Comment