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:
View worked solution
Answer: D
To find the minimum number of threads () and locks () 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, (Thread )
- Number of locks, (Lock )
Let the thread execute the following sequence of operations:
acquire(L1)— successfully acquires the lock .acquire(L1)— Since is non-reentrant and already held by , blocks waiting for to be released.
Since is blocked, it can never progress to release . This results in a self-deadlock.
Thus, the minimum number of threads and locks required to cause a deadlock is and .
Therefore, the correct option is D.
Free practice · Your answers on this page are not saved.
