Subj : Re: recursive mutexes To : comp.programming.threads From : Uenal Mutlu Date : Sun May 15 2005 05:59 pm "Peter Dimov" wrote > Uenal Mutlu wrote: > > "David Schwartz" wrote > >> Yes, it can and must know that it already has the lock. A > >> function that operates on X should be defined as being called with X > >> locked, or with X unlocked. It could even take a boolean that > >> indicates whether the caller has locked the object or not, though > >> this is rarely the right thing to do. > > > > You are unnecessarily complicating things and make the program > > slower by doing these testings. > > No, he's in fact making the program faster. Are you sure? Let's see: void X::f() { Lock(); for (int i = 0; i < 1000; i++) f(); Unlock(); } void X::g() { if (!IsLocked()) return; //...do..something... } Are you saying the above version of g() is faster than this one: ? void X::g() { //...do..something... } .