Question 16330 – UPPCL AE 2022
February 25, 2024Question 8938 – Cache
February 26, 2024Question 10544 – Critical-Section
Consider the following scheme for implementing a critical section in a situation with three processes and Pj and Pk.
Pi;
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;
(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.
Correct Answer: A
Theory Explanation.
