Question

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
Official answer and solution
Official answer
D
From
Official GATE 2017 answer key

Solution

Examine self-deadlock conditions caused by non-reentrant locks.

A non-reentrant lock is defined such that if a thread currently holds lock ll, it cannot re-acquire lock ll without releasing it first. If it attempts to acquire ll again, it blocks until ll is released.

Consider a program with x=1x = 1 (a single thread T1T_1) and y=1y = 1 (a single non-reentrant lock L1L_1):

  1. T1T_1 successfully acquires L1L_1.
  2. While still holding L1L_1, T1T_1 executes another acquire(L_1) operation (e.g., in a nested function call or loop).
  3. Because L1L_1 is non-reentrant and currently held, T1T_1 blocks waiting for L1L_1 to be released.
  4. But T1T_1 is the only thread that holds L1L_1 and could release it. Because T1T_1 is blocked, L1L_1 will never be released.

This creates a permanent block (self-deadlock). Therefore, the minimum values of xx and yy that can result in a deadlock are x=1x = 1 and y=1y = 1.

Final answer

D

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 1
Question
27 of 65, printed as CS Q.27
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.