Consider the following proposed solution for the critical section problem. There are processes : . In the code, function returns an integer not smaller than any of its arguments .For all is initialized to zero.
Code for ;
do {
c[i]=1; t[i]= pmax (t[0],....,t[n-1])+1; c[i]=0;
for every j != i in {0,....,n-1} {
while (c[j]);
while (t[j] != 0 && t[j] <=t[i]);
}
Critical Section;
t[i]=0;
Remainder Section;
} while (true);
Which of the following is TRUE about the above solution?
View worked solution
Answer: A
This algorithm is a modified version of Lamport's Bakery Algorithm. Let's analyze its properties:
-
Mutual Exclusion (Option A):
- The flag acts as the
choosingflag. The loopwhile (c[j]);ensures that process waits if is currently choosing its ticket, preventing from reading an incomplete ticket value. - If two processes and have different ticket values, say , then will pass the check for (since is false), while will block on (since is true).
- If they choose the identical ticket value (), then the condition
t[j] <= t[i]is true for , andt[i] <= t[j]is true for . Consequently, both processes block each other. - In all scenarios, it is impossible for more than one process to reside in the critical section simultaneously. Thus, mutual exclusion is satisfied.
- The flag acts as the
-
Deadlock and Progress (Options B, C, and D):
- Because there is no tie-breaker (like process ID comparison) when tickets are equal, if two processes obtain the same ticket value, they will deadlock.
- Since a deadlock can occur, the algorithm does not satisfy progress, is not deadlock-free, and does not guarantee bounded waiting.
Free practice · Your answers on this page are not saved.
