[cpp-threads] Failed compare-and-swap
Alexander Terekhov
alexander.terekhov at gmail.com
Tue Jul 31 18:56:29 BST 2007
On 7/31/07, Herb Sutter <hsutter at microsoft.com> wrote:
> Paul wrote:
> > Successful CAS has the specified memory-ordering properties. The
> > strong-atomics CAS would have a full fence when successful. A given
> > weak-atomics CAS would have the specified memory-ordering properties,
> > for example, a relaxed CAS would have no memory-ordering properties.
>
> Right, when I said full fence semantics I meant for strong atomics.
I just wonder whether you realize the cost of "full fence" strong
atomic semantics for CAS on Power and other stuff ala Xbox. ;-)
It's actually dual fenced (with most expensive "sync" fence for
leading and trailing barriers) and always-write (even in failure case)
semantics.
>
> > There are algorithms in which a failed CAS plays a role similar to a
> > failed trylock. So it would make quite a bit of sense for a failed CAS
> > to have the same memory-ordering semantics that it would have had if
> > successful. After all, the common case should be successful CAS! ;-)
>
> Sorry if the answer is obvious: What are some cases where a failed trylock
> needs ordering semantics?
Nothing portable under ISO/IEC 9945.
"Unless explicitly stated otherwise, if one of the above functions
returns an error, it is unspecified whether the invocation causes
memory to be synchronized."
pthread_mutex_trylock() doesn't fall under "explicitly stated otherwise".
regards,
alexander.
More information about the cpp-threads
mailing list