Subj : Re: recursive mutexes To : comp.programming.threads From : David Schwartz Date : Sun May 15 2005 01:06 pm "Uenal Mutlu" <520001085531-0001@t-online.de> wrote in message news:d67npb$enc$01$1@news.t-online.com... > 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... > } I never argued the performance issue. But here's a more realistic example: Without recursive mutexes: protected: f_locked(void) { // call with mutex locked DoStuff(); } public: f(void) { // call with mutex unlocked Lock(); f_locked(); Unlock(); } many_f(void) { // call with mutex unlocked Lock(); for(int i=0; i<1000; i++) f_locked(); Unlock(); } With recursive mutex: public: f(void) { // call with mutex in any state Lock(); DoStuff(); Unlock(); } many_f(void) { // call with mutex in any state Lock(); for(int i=0; i<1000; i++) f(); Unlock(); } Which do you think is faster? DS .