Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : David Schwartz Date : Sat Jan 22 2005 05:53 pm "Gianni Mariani" wrote in message news:4sadnW1IWuV3UGzcRVn-vg@speakeasy.net... > On the first time through, a memory barrier sync is done. Worst case, you > can't come out of this code normally without the construction being > completed. Once you decide that you're locking the mutex, I assume > barriers are looked after. The m_val value is thread local, meaning each > thread executed the memory barrier at least once - once the memory barrier > is synced once, why would it need to be synced again ? If it did, > somthing much more serious is broken. Ah, I missed that m_val is thread local. The problem with this routine is that each pass through it requires access to a thread local variable. This may even cost more than a memory barrier on many platforms, and it's likely more efficient to just have the memory barrier be unconditional. DS .