38e Subj : Re: stl & threads To : comp.programming.threads From : David Schwartz Date : Tue May 24 2005 08:11 pm "Uenal Mutlu" <520001085531-0001@t-online.de> wrote in message news:d70ha8$69s$05$1@news.t-online.com... [snip] > bool IsLockedByAny() const { return cLocked > 0; } > bool IsLockedByMe() const { return cLocked > 0 && dwThrId == > GetCurrentThreadId(); } [snip] > private: > CRITICAL_SECTION cs; > size_t cLocked; > DWORD dwThrId; > const bool fRecursiveMutex; > }; [snip] Suppose I write code like this: while(IsLockedByAny() && !IsLockedByMe()) i++; What guarantees that the compiler doesn't optimize away the repeated reads of 'cLocked' and spin forever? I admit that it's dumb to do something like that, but it's also bad for a mutex class to contain errors. DS . 0