Consider the following scheme for implementing a critical section in a…
PYQ GATE 1991Modified — slightly modified from the official paper; see the solution
Consider the following scheme for implementing a critical section in a situation with three processes Pᵢ, Pⱼ and Pₖ;
repeat
flag [i]:=true;
while flag [j] or flag [k] do
case turn of
j : if flag [j] then
begin
flag [i]:=false;
while turn ≠ i do skip;
flag [i]:=true
end;
k : if flag [k] then
begin
flag [i]:=false;
while turn ≠ i do skip;
flag [i]:=true
end
end
critical section
if turn = i then turn:=j;
flag [i]:=false
non-critical section
until false;
Assume atomic reads and writes, all flags initially false, and turn initially one of i, j, k. (a) Does the scheme ensure mutual exclusion in the critical section? Briefly explain.
(b) Is there a situation in which a waiting process can never enter the critical section? If so, explain and suggest modifications to the code to solve this problem.
Sign up free to check your answer
Sign up freeLoading lesson…

