Skip to content
Related Articles
Open in App
Not now

Related Articles

GATE | GATE-CS-2017 (Set 1) | Question 54

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

A multithreaded program P executes with x number of threads and uses y 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 l, then it cannot re-acquire lock l without releasing it. If a thread is unable to acquire a lock, it blocks until the lock becomes available. The minimum
value of x and the minimum value of y together for which execution of P can result in a deadlock are:
(A) x = 1, y = 2
(B) x = 2, y = 1
(C) x = 2, y = 2
(D) x = 1, y = 1


Answer: (D)

Explanation: Reentrant (Recursive) locks allow a thread to reacquire the lock. That means same process can claim the lock multiple times without blocking on itself. This prevents the thread from deadlocking itself. This is main advantage of reentrant locks over non-reentrant locks.

Non-reentrant (Non- recursive) locks not allow a thread to reacquire the lock. That means same process can not claim the lock multiple times without releasing it. So, if a thread/process is unable to acquire a lock, it blocks until the lock becomes available. This situation is deadlocked.

Therefore, only one thread and only one lock can cause deadlock, if thread does try to reacquire lock.

When we have more than one process or one lock, then process/thread can acquire another lock to proceed further, or other process/thread can acquire lock to proceed further.

This explanation is contributed by Mithlesh Upadhyay.

Quiz of this Question

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!