[concurrency-interest] Unsafe.getAndAddLong

Andrew Haley aph at redhat.com
Thu May 22 09:55:09 EDT 2014


More memory model mysteries:

Why do we use getLongVolatile here?  It'll be a load followed by an
acquire barrier.  But compareAndSwapLong is in effect a full barrier
anyway, so what's the point of using getLongVolatile?

    public final long getAndAddLong(Object o, long offset, long delta) {
        long v;
        do {
            v = getLongVolatile(o, offset);
        } while (!compareAndSwapLong(o, offset, v, v + delta));
        return v;
    }

Andrew.


More information about the Concurrency-interest mailing list