Subj : Re: recursive mutexes To : comp.programming.threads From : Uenal Mutlu Date : Wed May 18 2005 10:12 pm "doug" wrote> > "Uenal Mutlu" wrote in message > > "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? > > He's getting at this - how do you decide if you own the lock? If multiple > threads can possibly be reading/writing the same location, you need > synchronisation. If not, why are you even using a lock in the first place? > > You say "The code which increments the counter cannot be executed by anyone > else but the current lock holding thread." But how does the current thread > know if has the lock? I assume this is code internal to the Lock() routine, > but surely it must be accessing some shared data - a field in the lock > saying who owns it, for example? > > See my post above. Write some pseudocode for Lock() and we'll see. For the code see my other reply to you. .