Subj : Re: recursive mutexes To : comp.programming.threads From : David Schwartz Date : Thu May 19 2005 11:14 pm "Uenal Mutlu" <520001085531-0001@t-online.de> wrote in message news:d6gbdt$buc$00$1@news.t-online.com... > "Casper H.S. Dik" wrote >> "Uenal Mutlu" writes: >> (The recursive mutex is only slightly more expensive >> than the ordinary mutex as the unlock path is more >> expensive) > Actually it is just an increment and a comparision of the currentthreadid > vs. > the lock holding threadid in Lock(), and a simple decrement in Unlock(). > The overhead for recursively locking is far less than the first aquisition > (== non-recursive mutex) of the lock. Cf. code snippet of my other posting > to doug and > David. I'm afraid that's not true. A typical recursive unlock will need one interlocked operation to figure out whether it has to wake other threads or not followed by waking the threads if necessary. A typical non-recursive unlock will need one non-interlocked operation to release the lock followed by waking any threads. On a p4, it is typically about 70 cycles faster to release a non-recursive mutex than a recursive one assuming it's the last release and no threads are blocked. DS .