Subj : Re: recursive mutexes To : comp.programming.threads From : David Schwartz Date : Sun May 15 2005 01:03 pm "Uenal Mutlu" <520001085531-0001@t-online.de> wrote in message news:d67mtf$roq$03$1@news.t-online.com... > Since you don't believe me it's your turn to prove that recursive locking > is more dangerous (your saying) than using no recursive locking. > My point is: recursive locking is much safer than non-recursive locking. We've already done this over and over. Consider: x.Lock(); DoSomeStuff(); x.Unlock(); DoSomeStuffThatTakesALongTime(); If the lock for x is not recursive, we know that we can safely take a long time without stalling other threads that might want the x lock. If the lock is recursive, we might unknowingly hold the x lock while we do the stuff that takes a long time. Here's another one: x.Lock(); while (x.IsReservedByAnotherThread()) { x.Unlock(); DoOtherStuffSinceXIsNotReady(); } x.DoStuff(); x.Unlock(); This code will deadlock if the x mutex is recursive. The other thread can never clear its reservation because this thread might still hold the x mutex through the entire 'while' loop. We really mean what we're saying. Really, really. Recursive mutexes are really bad and they really do hide serious bugs. You could write either of the two code sections above and *never* detect the problem because it may only result in performance issues during your tests. But in another environment where the functions erroneously held with locks take longer, the result could be catastrophic. DS .