Hi all,

> Say thread A requires resource 1 and 2 to run.
> Thread B requires resource 1, 2 and 3 to run.
> What happens when thread A starts, get's a hold of resource 
> 1, then thread B starts, gets a hold of resource 2 and 3, then sits
waiting 
> for thread A to let go of resource 1.   Similarly, thread A will now wait
for 
> thread B to finish with resource 2.  Thus they are waiting on one another
in a
> 'deadlock' situation because neither will give up the resouce 
> that they just acquired, but both need to run to completion.

Did you notice the change you made to get a deadlock ? You changed the order
of locking !

If resources are always locked in the same order, deadlocks cannot occur.
That's the only rule ! But it's not always easy to implement !
Try to get a thread dump, then look for waiting threads, and monitors...
Tracking deadlocks is not easy...

Good luck,
Christophe

Reply via email to