Question
A multithreaded program executes with number of threads and uses 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 , then it cannot re-acquire lock without releasing it. If a thread is unable to acquire a lock, it blocks until the lock becomes available. The minimum value of and the minimum value of together for which execution of can result in a deadlock are:
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 , it cannot re-acquire lock without releasing it first. If it attempts to acquire again, it blocks until is released.
Consider a program with (a single thread ) and (a single non-reentrant lock ):
- successfully acquires .
- While still holding , executes another
acquire(L_1)operation (e.g., in a nested function call or loop). - Because is non-reentrant and currently held, blocks waiting for to be released.
- But is the only thread that holds and could release it. Because is blocked, will never be released.
This creates a permanent block (self-deadlock). Therefore, the minimum values of and that can result in a deadlock are and .
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.