[concurrency-interest] AQS.compareAndSetHead CAS abbreviation

Justin Sampson jsampson at guidewire.com
Wed Dec 31 04:51:18 EST 2014


DT wrote:

> In the AQS class method compareAndSetHead has java doc : /* CAS
> head field ... */ does it mean compare and set or compare and
> swap? It calls unsafe.compareAndSwapObject

Well, it appears that the Unsafe.compareAndSwapX methods are
actually compare-and-set operations anyway, aren't they? They all
return boolean to indicate success or failure, rather than returning
the old value of the field as a full compare-and-swap operation
would do.

It looks like java.util.concurrent code pretty consistently uses the
"compare and set" wording even though whoever wrote sun.misc.Unsafe
chose the "compare and swap" wording to mean exactly the same thing.
So I would presume that whoever wrote that "CAS head field" comment
was thinking "compare and set" at the time. :)

Cheers,
Justin



More information about the Concurrency-interest mailing list