Skip to main content

GATE CSE 2016Operating System › Process Synchronization & ConcurrencyVerified

GATE CSE 2016 PYQ: Consider the following proposed solution for the critical section problem. There are n n n processes : P 0 .…

Consider the following proposed solution for the critical section problem. There are nn processes : P0....Pn−1P_0....P_{n-1}. In the code, function pmax\text{pmax} returns an integer not smaller than any of its arguments .For all i,t[i]i,t[i] is initialized to zero.

Code for PiP_i;

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?

  1. A
    At most one process can be in the critical section at any time
    Correct answer
  2. B
    The bounded wait condition is satisfied
  3. C
    The progress condition is satisfied
  4. D
    It cannot cause a deadlock

Answer

(A) At most one process can be in the critical section at any time

Approach

The code is a modified Lamport bakery algorithm. The key points are the choosing flag c[i], the ticket value t[i] returned by pmax, and the waiting condition while(t[j] != 0 &amp;&amp; t[j] &lt;= t[i]). Because pmax may return the same maximum to multiple processes, ticket ties are possible, and the condition &lt;= makes tied processes wait on each other. Analyze mutual exclusion, progress, bounded waiting, and deadlock accordingly.

The solution preserves mutual exclusion because a process can enter only if its ticket is strictly smaller than the nonzero tickets of all others; two processes cannot both satisfy this. However, ties in the pmax-based ticket assignment can make multiple processes wait on each other, causing deadlock, violating progress, and violating bounded waiting. Hence the only true statement is A.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.