|
Boost Users : |
Subject: Re: [Boost-users] *****SPAM***** Re: shared_ptr singleton
From: Frank Mori Hess (fmhess_at_[hidden])
Date: 2008-10-16 22:56:09
On Thursday 16 October 2008 18:42, Peter Dimov wrote:
>
> The problem is that the default constructor may be invoked after the
> first call to Register::global, overwriting _global and resetting it to
> empty. The first subsequent call to global() would now reinitialize it.
>
> You can avoid this by making _global a local static:
>
> static RegisterP global()
> {
> static RegisterP _global( new Register );
> return _global;
> }
Hmm, so I guess it is impossible to make a thread-safe singleton that
avoids the static initialization order fiasco, unless your compiler
guarantees thread-safe initialization of local statics. Even
boost::call_once would require the once_flag to be statically initialized
before the call_once call happens.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net