[cpp-threads] Memory modelcounterproposal:synchronizationoperations
Alexander Terekhov
alexander.terekhov at gmail.com
Fri May 27 20:25:55 BST 2005
On 5/27/05, Peter Dimov <pdimov at mmltd.net> wrote:
[...]
> Typical DCL:
>
> X * volatile p = 0;
> mutex mx;
>
> X * get()
> {
> if( p == 0 )
> {
> mx.lock();
>
> if( p == 0 )
> {
> p = new X;
> }
>
> mx.unlock();
> }
>
> return p;
> }
>
> Idiomatic MT C++ replacement:
>
> X * get()
> {
> /*protected*/ static X * p = new X;
static(synchronized) X * p = new X;
> return p;
> }
Plus future_std::once<T> functor for dynamic context.
regards,
alexander.
More information about the cpp-threads
mailing list