Question

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

Code for Pi :
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 one of the following is TRUE about the above solution?

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2016 answer key

Solution

Analyze the conditions for mutual exclusion, progress, bounded waiting, and deadlock in the given synchronization algorithm.

Examine the entry protocol for process PiP_i:

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]);
}

Key observation on the waiting condition:
while (t[j] != 0 && t[j] <= t[i]);
In Lamport's Bakery algorithm, tie-breaking between identical tickets is done by comparing process IDs: (t[j] < t[i]) || (t[j] == t[i] && j < i). In this code, however, the strict <= condition is used without process ID tie-breaking.

Deadlock scenario:

  • Suppose two processes PiP_i and PkP_k attempt to enter their critical sections simultaneously and obtain the exact same ticket value: t[i]=t[k]=v>0t[i] = t[k] = v > 0.
  • When PiP_i examines PkP_k, it sees t[k]≠0t[k] \ne 0 and t[k]≤t[i]t[k] \le t[i] (since v≤vv \le v), so PiP_i waits for PkP_k.
  • Simultaneously, when PkP_k examines PiP_i, it sees t[i]≠0t[i] \ne 0 and t[i]≤t[k]t[i] \le t[k] (since v≤vv \le v), so PkP_k waits for PiP_i.
  • Both processes wait on each other indefinitely, resulting in a deadlock. Consequently, progress is not guaranteed, bounded waiting is not satisfied, and deadlock can occur.

Mutual Exclusion check:

  • Suppose process PiP_i enters the critical section. This means that for every other process jj, when PiP_i checked jj, either t[j]=0t[j] = 0 or t[j]>t[i]t[j] > t[i].
  • If another process PjP_j tries to enter while PiP_i is inside, it will find t[i]≠0t[i] \ne 0 and t[i]≤t[j]t[i] \le t[j] (or it will wait in while (c[i])), preventing PjP_j from entering.
  • Even in the tie case t[i]=t[j]t[i] = t[j], neither process can enter the critical section.
  • Therefore, two processes can never be simultaneously in the critical section. Mutual exclusion is preserved: at most one process can be in the critical section at any time.
Final answer

A

Common trap

Assuming the algorithm is a correct implementation of Lamport's Bakery algorithm, overlooking the missing process ID tie-breaker which permits deadlock when two tickets are equal.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2016 Computer Science and Information Technology (CS) Session 1
Question
60 of 65, printed as CS Q.50
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.