1,236 views
1 votes
1 votes

Consider the following algorithm as a solution to the Critical Section problem.


The process shares two variables:
var flag: array [0….1] of Boolean;
turn= 0…..1;
Initially flag [0]= flag [1]= false;
turn= 0 (or) 1;
the structure of process Pi is like
repeat
flag[i] = true;
turn= j;
while (CONDITION);
CS
flag [i]= false;
………
………
until false.


What should be the Condition, so that algorithm satisfies all the three requisites i.e. ME, Progress
& BW?
(a) flag [j]= true & turn= j; (b) flag [j]= false & turn= i;
(c) flag [i]= true & turn= j; (d) flag [i]= false & turn= i;


Solution: Option (a)  (need the explanation)

1 Answer

Best answer
1 votes
1 votes

This a typical case for Peterson's Solution:

Although, this is quite easy topic, I would recommend to go through Galvin for better understanding.

selected by

Related questions

0 votes
0 votes
1 answer
1
ajayraho asked Oct 23, 2022
911 views
What is the significance of infinite loop that is written in every example of process synchronisation? What would happen if there wasn't any infinite loop?