[concurrency-interest] AtomicReference weakCompareAndSet "Mayfailspuriously"?

Thomas Hawtin tackline at tackline.plus.com
Wed May 17 09:01:17 EDT 2006

Doug Lea wrote:
> A plain compareAndSet has volatile-write memory model semantics, while a
> weakCompareAndSet has non-volatile-write memory model semantics.

And the same for (non-)volatile-read memory model semantics, if my 
reading of the package JavaDocs is correct.

Is there any particular reason for not having a "weakGet" method? Going 
back to Hanson Char's example:

  int maxLatencySnapshot = this.maxLatency.get();
  if (latency > maxLatencySnapshot) {
    if (this.maxLatency.weakCompareAndSet(maxLatencySnapshot, latency)) {

Most of the gains that may be made from using weakCompareAndSet seem to 
be blown away by the get. (Sun's implementation doesn't seem to 
differentiate between weakCompareAndSet and compareAndSet, at the moment.)

Tom Hawtin

More information about the Concurrency-interest mailing list