[concurrency-interest] jdk9 VarHandle and Fence methods

thurstonn thurston at nomagicsoftware.com
Sun Aug 23 13:42:29 EDT 2015


As far as a code sample for the compareAndExchangeXXX variants:


//An improved updateAndGet
Object owner = . . .
VarHandle<T> referent = . . .
UnaryOperator<T> identity = it -> it;

T expected = referent.getXXX();
T updated = identity.apply(expected);


for (; (expected = referent.compareAndExchangeXXX(owner, expected, updated))
!= updated; updated = identity.apply(expected)) {}

return updated; //updated == expected


Not exactly sure whether AtomicReference will use VarHandles or not, but all
of the "higher order methods" should be rewritten similarly




--
View this message in context: http://jsr166-concurrency.10961.n7.nabble.com/jdk9-VarHandle-and-Fence-methods-tp12666p12690.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.


More information about the Concurrency-interest mailing list