From: Peter Dimov (pdimov_at_[hidden])
Date: 2007-08-27 12:33:11
> Most processors have linear write buffers and if 'initialized' is seen
> as true the object has been written, too.
The write buffer in thread 1 doesn't affect the reads in thread 2, which can
still be reordered.
True if by "most processors" you mean "x86", though, absent compiler
To be on the safe side one needs:
if( atomic_load_acquire( &initialized ) != 0 )
// access object
in thread 2 and
// initialize object
atomic_store_release( &initialized, 1 );
in thread 1.
Hasn't Anthony Williams already implemented a header-only call_once? I'm not
sure I see a reason to reinvent that particular wheel. Once boost::mutex is
made header-only, there'd be no need for lightweight_mutex either and I'll
be able to retire it as well.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk