AtomicLong vs AtomicLongFieldUpdater addAngGet

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

AtomicLong vs AtomicLongFieldUpdater addAngGet

Patrick Julien
In Java 8, AtomicLong and AtomicInteger were modified to use the new
unsafe operations, e.g.,

public final long addAndGet(long delta) {
    return unsafe.getAndAddLong(this, valueOffset, delta) + delta;
}

but not the field updater variants which still do a compare and set

public long addAndGet(T obj, long delta) {
    long prev, next;
    do {
        prev = get(obj);
        next = prev + delta;
    } while (!compareAndSet(obj, prev, next));
    return next;
}

Is there any reason for this or is it just an omission?
_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: AtomicLong vs AtomicLongFieldUpdater addAngGet

Doug Lea
On 09/05/2015 07:41 AM, Patrick Julien wrote:

> In Java 8, AtomicLong and AtomicInteger were modified to use the new
> unsafe operations, e.g.,
>
> public final long addAndGet(long delta) {
>      return unsafe.getAndAddLong(this, valueOffset, delta) + delta;
> }
>
> but not the field updater variants which still do a compare and set
>
> Is there any reason for this or is it just an omission?
>

In retrospect it is an omission. There was initially
an internal snag preventing these, but it disappeared.
We should/will correct this when reconciling with Varhandles
for jdk9.

-Doug



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest