Subj : Re: Deadlock theorem To : comp.programming.threads From : Uenal Mutlu Date : Mon May 02 2005 05:03 pm "Peter Koch Larsen" wrote > "Uenal Mutlu" skrev > > "Joe Seigh" wrote > >> > >> Releasing a lock doesn't block, so there's no requirement on any > >> release order, though you can't reacquire the lock if you hold locks > >> further down in the hierarchy without releasing those locks first. > > > > Do you mean that the following case is not possible with hierarchical > > locking? > > o1.Lock(); > > o2.Lock(); > > o3.Lock(); > > o1.Unlock() > > o2.Unlock(); > > o1.Lock(); > > > > With my method this is possible. And this also shows that the > > methods indeed aren't the same. > > > > > What do you mean? Let us test your solution: > Thread 1: > o1.Lock(); > o2.Lock(); > o3.Lock(); > o1.Unlock() > o2.Unlock(); > >> context switch > > Thread 2: > o1.Lock(); > o2.Lock(); > o3.Lock(); => waits for unlock by thread 1 > > Thread 1 resumes: > o1.Lock(); => waits for unlock by thread 2 > > A nice and simple deadlock. Of course you are right. I'm aware of the deadlock when there is more than 1 thread. The purpose of the code was just to show one of the differences between the definition of hierarchical locking and my method. .