Exams › GATE › Technical
Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d and a before entering the respective code segments. After completing the execution of the code segment, each process invokes the V operation (i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to 1. Which one of the following is a deadlock-free order of invoking the P operations by the processes?
- X: P(a)P(b)P(c) Y: P(b)P(c)P(d) Z: P(c)P(d)P(a)
- X: P(b)P(a)P(c) Y: P(b)P(c)P(d) Z: P(a)P(c)P(d)
- X: P(b)P(a)P(c) Y: P(c)P(b)P(d) Z: P(a)P(c)P(d)
- X: P(a)P(b)P(c) Y: P(c)P(b)P(d) Z: P(c)P(d)P(a)
Correct answer: X: P(b)P(a)P(c) Y: P(b)P(c)P(d) Z: P(a)P(c)P(d)
Solution
The correct option avoids circular wait conditions by ensuring that each process acquires semaphores in a consistent order. By having X acquire b before a, Y acquire b before c, and Z acquire a before c, it prevents any possibility of deadlock since no process will hold a semaphore while waiting for another that is held by a different process.
Related GATE Technical questions
⚔️ Practice GATE Technical free + battle 1v1 →