Subj : Re: recursive mutexes To : comp.programming.threads From : Uenal Mutlu Date : Mon May 16 2005 05:30 pm "Torsten Robitzki" wrote > Uenal Mutlu wrote: > > > "doug" wrote > > > >>>You seem to not understand what I'm talking about. > >>>Do you understand this fact: "Recursive locking is defined for the current > >>>lock owning thread only"? > >>>Since you already have the lock you can do what ever you want since nobody > >>>else can change anything, but you can do! You simply increment it in > >>>Lock() > >>>and decrement it in Unlock(). Because it is safe because you already have > >>>it locked. > >>> > >> > >>Think carefully. How is this possible? > > > > It is really basic stuff. Ask yourself how you would extend a non-recursive > > locking method to make it recursive? Recursivity starts with the 2nd Lock() > > call on the same object within the same thread, true? > > First one have to check if this lock request comes from the thread > holding the mutex or not. This can not be implemented by a simple > increment. I can only repeat: The code which increments the counter cannot be executed by anyone else but the current lock holding thread. Do you know what a critical section is? In your other posting you wrote: > P.S. never used recursive locks and never had any serious problems with > deadlocks. May I ask: have you ever either implemented any mutex (recursive or non-recursive) by yourself or have you ever used a non-recursive mutex in your projects? For which OS and using which threading pkg do you develop? .