[cpp-threads] Globals and Threads

Peter Dimov pdimov at mmltd.net
Mon Oct 24 20:09:13 BST 2005


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.



More information about the cpp-threads mailing list