Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q27 — Concurrency and Synchronization

Explain with AI

A multithreaded program PP executes with xx number of threads and uses yy number of locks for ensuring mutual exclusion while operating on shared memory locations. All locks in the program are non-reentrant, i.e., if a thread holds a lock ll, then it cannot re-acquire lock ll without releasing it. If a thread is unable to acquire a lock, it blocks until the lock becomes available. The minimum value of xx and the minimum value of yy together for which execution of PP can result in a deadlock are:

Choose one option
View worked solution

Answer: D

To find the minimum number of threads (xx) and locks (yy) that can cause a deadlock, let us analyze the behavior of non-reentrant locks.

A lock is non-reentrant if a thread that already holds the lock cannot acquire it again without releasing it first. If it attempts to do so, it blocks indefinitely waiting for the lock to be released.

Consider the case where:

  • Number of threads, x=1x = 1 (Thread T1T_1)
  • Number of locks, y=1y = 1 (Lock L1L_1)

Let the thread T1T_1 execute the following sequence of operations:

  1. acquire(L1) — T1T_1 successfully acquires the lock L1L_1.
  2. acquire(L1) — Since L1L_1 is non-reentrant and already held by T1T_1, T1T_1 blocks waiting for L1L_1 to be released.

Since T1T_1 is blocked, it can never progress to release L1L_1. This results in a self-deadlock.

Thus, the minimum number of threads and locks required to cause a deadlock is x=1x = 1 and y=1y = 1.

Therefore, the correct option is D.

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

Published
Report a correction
Keep exploringMore Concurrency and Synchronization questions