Boost logo

Boost :

Subject: Re: [boost] a new library Global Object Manager submission interest check
From: Glen Fernandes (glen.fernandes_at_[hidden])
Date: 2014-06-07 19:58:14


Hi George,

On Sat, Jun 7, 2014 at 3:28 PM, George Georgiev wrote:
> I have code that deals with problems related to initialization of global
> objects (singletons).
> 1. Multi-threading - problems occurring in some singleton patterns based on
> the fact that local for a function or method static variables are not
> initialized in a thread safe manner

Did you mean specifically for C++03 / non-C++11 compilers? With C++11,
initialization of function-local statics is guaranteed to be
thread-safe.

For those compilers that do not implement that C++11 requirement (like
VC12), how does your solution for thread-safe singleton initialization
compare (performance-wise) to, say,
http://www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html#boost_atomic.usage_examples.singleton
or other alternatives?

In any case, I'm curious to see your solution. Is it on GitHub?

[ Side note: Instead of boost::shared_ptr<T>(new T(...)) always prefer
boost::make_shared<T>(...). For better performance (one allocation
instead of two) and exception-safety. Granted, this is a test snippet,
but I also noticed it in Compil. :-) ]

Glen


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk