Skip to content
Official PYQ · 2013

GATE CS 2013 Q16 — Deadlock

Explain with AI

Three concurrent processes XX, YY, and ZZ execute three different code segments that access and update certain shared variables. Process XX executes the PP operation (i.e., waitwait) on semaphores aa, b,b, and cc; process YY executes the PP operation on semaphores bb, c,c, and dd; process ZZ executes the PP operation on semaphores cc, dd, and aa before entering the respective code segments. After completing the execution of its code segment, each process invokes the VV operation (i.e., signalsignal) on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of the following represents a deadlock-free order of invoking the PP operations by the processes?

Choose one option
View worked solution

Answer: B

To ensure a system is deadlock-free, we must prevent a circular wait condition. Let us analyze the options by checking if a circular wait can be formed when processes execute concurrently.

Consider Option B:

  • X:P(b)P(a)P(c)X: P(b)P(a)P(c)
  • Y:P(b)P(c)P(d)Y: P(b)P(c)P(d)
  • Z:P(a)P(c)P(d)Z: P(a)P(c)P(d)

Let's trace the execution of the first PP operations:

  1. Both XX and YY compete for semaphore bb as their first operation. Since bb is a binary semaphore initialized to 11, only one of them can acquire it.
  2. Case 1: XX acquires bb first. YY is blocked on P(b)P(b). Now, XX and ZZ compete for semaphore aa.
    • If XX acquires aa, XX holds both aa and bb. It can then easily acquire cc, complete its execution, and release all semaphores, allowing YY and ZZ to proceed.
    • If ZZ acquires aa, XX blocks on P(a)P(a). ZZ holds aa and can successfully acquire cc and dd (since they are free), complete its execution, and release them. This unblocks XX, which then completes, followed by YY.
  3. Case 2: YY acquires bb first. XX is blocked on P(b)P(b). Now, YY (holding bb) and ZZ (holding aa) compete for cc.
    • If YY acquires cc, YY holds bb and cc. It then acquires dd, completes, and releases them.
    • If ZZ acquires cc, ZZ holds aa and cc. It then acquires dd, completes, and releases them.

In all possible execution sequences of Option B, no circular wait is formed, making it completely deadlock-free.

For other options, we can easily find a deadlocked state. For example, in Option A, if XX acquires aa, YY acquires bb, and ZZ acquires cc, a circular wait occurs (X→b→Y→c→Z→a→XX \to b \to Y \to c \to Z \to a \to X), resulting in a deadlock.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Deadlock questions