Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-09-25 12:37:18

From: "Alexander Terekhov" <terekhov_at_[hidden]>
> > POSIX says "On return from pthread_once( ), it is guaranteed that
> > init_routine has completed." Does "completion" imply that the results
> > visible to all threads?
> well, it is the only way i can interpret that statement.

From this post:

I get the impression that David Butenhof definitely thinks that pthread_once
should synchronize memory. We can only hope that all pthread implementors

OK, let's say that this means that the last implementation I gave is

static boost::once_flag m_once = boost::once_init;
static boost::mutex * pm = 0;

void m_init()
    pm = new boost::mutex;

X & X::get()
    boost::call_once(&m_once, m_init);
    boost::mutex::scoped_lock lock(*pm);
    static X x;
    return x;

I still don't like it. Such a common pattern shouldn't be that hard. Some
day C++ may guarantee that a function local static is thread safe; but then
again, it might not, and besides, we need a stop gap solution in the

Peter Dimov
Multi Media Ltd.

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