Synchronization & Concurrency
![Question 50, GATE 2016: There are n processes Pi, and all t[i] initially equal 0. pmax returns an integer at least as large as each argument. Each Pi repeats:
c[i]=1; t[i]=pmax(t[0],...,t[n−1])+1; c[i]=0;
for every j!=i {while(c[j]); while(t[j]!=0 && t[j]<=t[i]);}
Critical Section; t[i]=0; Remainder Section;
Which claim is true? A:At most one process is in its critical section at any time. B:Bounded waiting holds. C:Progress holds. D:Deadlock cannot occur. Analyze the usual atomic-read/write, sequentially consistent, nonoverflowing-ticket model with initially clear choosing flags c.](../../assets/questions/CS-2016-S1-Q60-1.webp)
Answer & solution
Official answer: A
This is bakery-style ticket selection without a process-ID tie-breaker. The choosing flags ensure another process waits until ticket selection finishes. Under the usual atomic-read/write, sequentially consistent, nonoverflowing-ticket model, two active contenders cannot both pass each other: a smaller nonzero ticket blocks the larger, while equal tickets block both. Thus mutual exclusion holds. Two simultaneous selections can read the same old maximum and choose equal tickets; each then waits for the other forever, so progress, deadlock-freedom and eventual bounded waiting are not guaranteed. Only A. Choosing flags are understood initially clear.
For a concrete deadlock execution with two processes, both evaluate the old maximum 0 before either publishes its ticket, and both choose 1. After their choosing flags clear, each sees the other's nonzero equal ticket and waits because 1≤1. Neither reaches the code that resets its ticket to 0. A process-ID tie-breaker, as in the standard bakery algorithm, would order equal tickets; it is absent here. This shows why mutual exclusion can hold while progress and bounded waiting fail.