TransWikia.com

How to find a condition which leads to deadlock in non-reentrant locks

Computer Science Asked by mb14 on January 9, 2021

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

Though, answer is option D but is there any possibility to have deadlock in other 3 options. If yes, then what it is because not able to visualize other options. Kindly explain.

One Answer

A single thread can get itself deadlocked by locking the same lock twice without an unlock in between. Which is obviously a stupid thing to do.

I don’t see your problem with the other cases: if one thread deadlocks itself, you have a deadlock, no matter how many other threads and locks you have.

Answered by gnasher729 on January 9, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP