Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

deadlock  RSS feed

 
vijay kaushik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to know about deadlock in details with an example as i read it in complete reference by patrick Naughtan but not understan well. please satisfy my query.
 
Sumit David
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Imagine a situation: We have two threads t1 and t2 and two resources r1 and r2. Suppose t1 holds r1(for its own use) and t2 holds r2, with this assume that t1 needs r2 for its completion and t2 needs r1 for its completion and they both can't proceed without the needed resources. Obviously t1 can't release r1 and t2 can't release r2 (they can't proceed!)so they both are stuck. This is an example of a deadlock.

Thank you
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sumit David:
Hi
Imagine a situation: We have two threads t1 and t2 and two resources r1 and r2. Suppose t1 holds r1(for its own use) and t2 holds r2, with this assume that t1 needs r2 for its completion and t2 needs r1 for its completion and they both can't proceed without the needed resources. Obviously t1 can't release r1 and t2 can't release r2 (they can't proceed!)so they both are stuck. This is an example of a deadlock.

Thank you



Here is some code to illustrate this idea. Everytime you run it, it's in a deadlock. That's because the two trains aquire the semaphores in the opposite order, which is a typical reason for the deadlock:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!