Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-04-05 05:46:51


Alexander Terekhov wrote:
> Peter Dimov wrote:
>>
>> Eh, __asm__ is no better than a volatile. Both are non-portable.
>
> Except that volatile has defined semantics (both must die too in
> favor of threads and exceptions) that has really nothing to do
> with multiple threads and msync. I mean "decoration function" for
> sig_atomic_t statics and setjmp/longjmp()-sensitive locals in C
> and POSIX (C++ aside for a moment).

Yes, but in this case threads are not a problem (we're in release,
destroying the last remaining shared_ptr; if we read weak_count_ == 1, no
other thread can be creating/destroying weak pointers because of basic
guarantee). Msync is not a problem because we've just acquired in the
decrement.

Now that I think of it, compiler value propagation isn't a problem either
because of the "memory" clobber on the decrement. So the cast to volatile
can be removed.

    void release() // nothrow
    {
        if( atomic_exchange_and_add( &use_count_, -1 ) == 1 )
        {
            dispose();

            if( weak_count_ == 1 ) // no weak ptrs
            {
                destroy();
            }
            else
            {
                weak_release();
            }
        }
    }


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