Boost logo

Boost :

From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-03-24 10:56:10

On Thu, Mar 24, 2005 at 05:40:07PM +0200, Peter Dimov wrote:

> So, shared_ptr is now lock-free on Windows, but not on the other platforms.
> We need a portable atomic primitive for that. The only alternative are the
> internal libstdc++ helpers __atomic_add and __exchange_and_add.
> But in order to use them correctly, we need to know what their exact
> semantics are with respect to memory synchronization.
> To the best of my knowledge, this is not documented anywhere.
> What do we do now?

I can find out if you like - I am using the primitives for the libstdc++
version of shared_ptr so was going to dig into their semantics this
weekend and ask on the libstdc++ list.

>From my brief survey of the primitives, the memory synchronisation isn't
well defined ... it depends on the particular implementation on a
particular platform (the i386 implementations, for example, just use a
mutex, so aren't lock-free at all). If the implementation for platform
X uses memory barriers then it will be well-defined on platform X.

N.B. libstdc++ had a compare_and_swap primitive until a couple of years ago,
when it was removed because nothing was using it and it was a headache
when porting libstdc++ to new architectures.
I'm going to ask about the possibility of resurrecting that
compare_and_swap(), otherwise shared_count::add_ref_lock() needs to use
a lock.


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