Subj : Re: Boost.Threads on its way to C++0x To : comp.programming.threads From : Peter Dimov Date : Thu Apr 28 2005 04:40 pm gottlobfrege@gmail.com wrote: > Peter Dimov wrote: >> Isn't this the usual broken DCL? >> >> int func() >> { >> if( !__flag ) >> { >> call constructor >> lock >> do things >> unlock >> __flag = true; >> } >> } >> >> What prevents __flag = true migrating upwards above "do things"? > > Well, in your case, the lock and unlock would probably do it (ie by > adding memory barriers). > > But you still need an acquire on the read of flag. Under Windows > something like (off the top of my head): [...] The problem I was trying to highlight is that __flag and all its manipulations are implicitly done by the compiler. We don't have any control over it and we can't insert an acquire on the initial load. No matter what we do in the constructor, it can't be made to work reliably. Unless I'm missing something. .