Question
Consider the following proposed solution for the critical section problem. There are processes: . In the code, function pmax returns an integer not smaller than any of its arguments. For all , 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?
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 :
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 and attempt to enter their critical sections simultaneously and obtain the exact same ticket value: .
- When examines , it sees and (since ), so waits for .
- Simultaneously, when examines , it sees and (since ), so waits for .
- 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 enters the critical section. This means that for every other process , when checked , either or .
- If another process tries to enter while is inside, it will find and (or it will wait in
while (c[i])), preventing from entering. - Even in the tie case , 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.
A
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.