[cpp-threads] Globals and Threads

Andrei Alexandrescu andrei at metalanguage.com
Mon Oct 24 20:38:10 BST 2005


Peter Dimov wrote:
> Peter A. Buhr wrote:
> 
>>   3. Leave things as they are and allow users to guard things manually
>>   with a statically-initialized bool:
>>
>>   Widget * Foo() {
>>      static bool initialized = false;
>>      static Widget result = 0;
>>      if (std::assign_once(initialized, true)) {
>>         // Code executed only once
>>         static Widget w;
>>         result = &w;
>>      }
>>      return result;
>>   }
>>
>>   I incline towards 3 because it's most flexible and doesn't require
>>   syntax changes.
>>
>> I agree with Andrei.
> 
> 
> Before agreeing, please note that the code above doesn't work.

Look Peter, that's not helpful and just increases traffic on the list. 
If you are referring to my obvious syntax error in result's definition 
line (should be a Widget *, not a Widget), then it would help if you 
said so. If you refer to the fact that I wasn't clear on the semantics 
of assign_once, then saying so would, again, be helpful. If you refer to 
the absence of a memory barrier after result's assignment, then... you 
got my drift. Speak your mind.


Andrei



More information about the cpp-threads mailing list