in Operating System edited by
33,231 views
122 votes
122 votes

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:

  1. $x = 1, y = 2$
  2. $x = 2, y = 1$
  3. $x = 2, y = 2$
  4. $x = 1, y = 1$
in Operating System edited by
by
33.2k views

4 Comments

A REENTRANT LOCK IS ONE WHERE A PROCESS CAN CLAIM THE LOCK MULTIPLE TIMES WITHOUT BLOCKING ON ITSELF. IT'S USEFUL IN SITUATIONS WHERE IT'S NOT EASY TO KEEP TRACK OF WHETHER YOU'VE ALREADY GRABBED A LOCK. IF A LOCK IS NON RE-ENTRANT YOU COULD GRAB THE LOCK, THEN BLOCK WHEN YOU GO TO GRAB IT AGAIN, EFFECTIVELY DEADLOCKING YOUR OWN PROCESS.

 

 

explains clearly
1
1
edited by
A very ambiguous question. Thank you @Bikram Sir for the detailed explaination :)
2
2

so As per my level of understanding in this
as option A ,single process can go to CS atmost 2 times,
as opt B both process can go to CS one time, one after other.
as opt C, both process can go to CS 2 times, simultaneously also possible by taking different locks
as opt D, 1 process can go to CS only for 1 time

Am I right @Deepak Poonia @Sachin Mittal 1 @Arjun sir?

1
1

7 Answers

0 votes
0 votes
suppose

I. p(y)

II. p(y)

cs

III. v(y)

IV. v(y)

in this case if we execute step number I then only after executing V(y) we can perform step II, else this will lead to dead lock.
0 votes
0 votes
I guess than by the same logic all binary semaphores are non-reentrant by default. so a system with single process that requires only one binary semaphore can be deadlocked. Is my interpretation right ? please  comment. thanks.
–1 vote
–1 vote

Answer is option C. How can a single thread cause a deadlock? It just violate the necessary conditions for a deadlock.

For reference check Q47 of the link below:

http://gfweb.s3.amazonaws.com/gatepapers/GATE2017/CS-GATE%272017-Paper-01-key-solution.pdf

Answer:

Related questions