We almost never see 1 because chances of happening thread interleaving are very low.
% (b)
declare
C={NewCell 0}
thread I in
I=@C
{Delay 5000}
C:=I+1
end
thread J in
J=@C
C:=J+1
{Delay 5000}
end
Above code almost always results in C being 1 and reason is pretty trivial to figure out.
% (c) -
Since there is a lock, so other thread can't enter the locked block unless the first thread releases it so interleaving is not possible and hence we never see 1 even if we add delay.
No comments:
Post a Comment