[concurrency-interest] CompareAndSet - can there also be NO winner?
dl at cs.oswego.edu
Tue Nov 22 11:46:33 EST 2011
On 11/22/11 11:09, Dr Heinz M. Kabutz wrote:
> If we have an atomic integer (or any other atomic class) and two threads call
> compareAndSet(42, 43) at the same time, is it possible that both calls fail? Or
> is there /always/ a winner?
Assuming that the value was 42, yes, there must be a winner.
The weakCompareAndSet method makes no such guarantees.
On machines with LL/SC not CAS, plain CAS must be (and is) emulated
to preserve this guarantee, but weak-CAS may fail spuriously.
For more background, see Herlihy and Shavit's book.
More information about the Concurrency-interest