[concurrency-interest] AtomicReference weakCompareAndSet "Mayfailspuriously"?

Boehm, Hans hans.boehm at hp.com
Thu May 18 17:18:32 EDT 2006

> From: Cliff Click
> For AtomicRef's I agree with Bill's statement: for ease of 
> correct coding we should just require the happens-before.
It still strikes me as very weird to distinguish the two.  If I
implement a single bit counter as an integer, I would get different
semantics than if I implement it via switching between references to two
preinitialized Boolean objects.  In cases like these, the user's
requirements are absolutely the same for both.

If you want to do this, I think the operations should at least have
different names.

The real issue here may be the current documentation for
AtomicReference.weakCompareAndSet, which seems to be lacking the
requisite warnings, like: "This provides weaker memory visibility
guarantees than compareAndSet.  If you have any doubt whether you should
be using weakCompareAndSet or compareAndSet, then use compareAndSet."


More information about the Concurrency-interest mailing list