Subj : Re: double-checked locking in C To : comp.programming.threads From : Joe Seigh Date : Wed Jul 06 2005 10:05 am Laurent Deniau wrote: > Joe Seigh wrote: >> >> Most people don't realize that it's not just reads that can be out of >> order but writes as well. So you need release semantics on the store >> of the init flag as well as acquire semantics on the load of that flag. > > > This is done by the mutext lock and unlock. They unsure synchronization > of the memory content with other threads (otherwise mutex would be > completely useless). I do not have to deal with such problem (and it is > not possible at the level of C). The mutex doesn't affect the order of stores as seen by other threads *not* using the mutex. > >> There was nothing in your example showing that the initialization stores >> had to appear in memory before the store to the init flag did. > > > This is the problem of unlock, not mine. Between the lock/unlock I > *only* must ensure that if other threads see a value in the first test > (by a premature memory commit), it is a valid value, which by the way > never change after being set. The rest is done by lock/unlock. > > Remember the context: C language, singleton pattern (or unique > initialization) and DCL. Nothing more. > > If you still see a problem in my code, please show me a sequence of > actions (sequence points) done by two (or more) threads which breaks the > semantic of the singleton pattern. > No, sorry. The burden of proof is on you. And the reason I posted the URL is so we don't have to disprove every bogus DCL implementation there is over and over again. Another URL you can check out http://www.nwcpp.org/Downloads/2004/DCLP_notes.pdf -- Joe Seigh When you get lemons, you make lemonade. When you get hardware, you make software. .