Subj : Re: Optimization to Jeffrey Richter's COptex (Windows)? To : comp.programming.threads From : Joseph Seigh Date : Wed Jan 26 2005 01:49 pm On Wed, 26 Jan 2005 19:06:45 +0100, Alexander Terekhov wrote: > > Joseph Seigh wrote: > > [... ordinal reads ...] > >> No. If a thread releases the lock, it sets the owning thread id to zero. >> it can only see zero or the thread id of another thread. > > Absent application synchronization with respect to termination > and creation of threads, it may (in theory; formally speaking > based on the lack of constraint imposed on the threading impl) > see id of another already terminated thread that happens to > have the same value. > > t0: thread 666 unlocks the mutex and terminates; > > t1: thread 000 (it can still see 666) creates another thread > and it gets reclaimed id 666. It "inherits" the same view > of memory as thread 000 (sees 666); I'd like to see how you propose that the creation code manages to see that 666 has been freed up for reuse and still sees 666 in memory as the lock owner. > > t3: thread 001 locks the mutex. > > t4: new thread 666 attempts to lock the mutex and thinks that > it already owns it... > > not good, oder? > > regards, > alexander. > -- Joe Seigh .