Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-08-02 14:05:33

Jason Hise wrote:
> Jonathan Turkanis wrote:

>> You might want to look at this thread:
>> Jonathan
> That does indeed confirm that function-local statics are not
> initialized
> in a thread-safe manner on some current popular C++ compilers. So to
> avoid the whole mess regarding the DCLP, the best approach would
> probably be eager initialization, before the program enters a
> multi-threaded context. Is initializing from the constructor of a
> namespace-scope global enough to ensure this?

I don't think so, since you might want to access singletons from static
initializers in other translation units.

Have you considered using call_once: It might look like this:

  boost::once_flag foo_once = BOOST_ONCE_INIT;
  Thing* t = 0;

  void foo_init()
    t = new Thing;

  void foo()
     boost::call_once(&foo_init, foo_once);
     // Use *t

I'm not sure this will work, so check it with someone else.

> -Jason


Boost list run by bdawes at, gregod at, cpdaniel at, john at