17 Aug
2005
17 Aug
'05
8:22 p.m.
On 18/08/2005, at 1:19 AM, boost-users-request@lists.boost.org wrote:
I envisage two threads accessing a function like this concurrently:
template<typename T> boost::shared_ptr<T> my_func() { static boost::mutex m; boost::mutex::scoped_lock l(m);
static boost::shared_ptr<T> p(new T); return p; }
and my worry is that both threads could attempt to do the static initialisation of m concurrently. Is there protection against this? Is it even possible to protect against this? The scope of m is actually outside of your function given that it is static. Thus it will be initialised outside of your function generally before any other threads get to start up.
Cheers, -C