[concurrency-interest] Unsafe.getAndAddLong

Arcadiy Ivanov arcadiy at ivanov.biz
Thu May 22 13:14:19 EDT 2014


> This argument is a strange combination of pragmatic efficiency
> concerns and abstract language semantics.
It was not an argument, it was an answer. Your original question was 
"why is it there", not whether it's THE optimal implementation on all 
architectures. :)
Both Doug and myself provided you with several rationale in terms of JMM.
> I don't think that word-tearing matters here: all it will do in the
> odd chance that it occurs is cause a retry.
Hence my answer: no matter the three reasons, the worst case is your CAS 
will fail the first time (unless another CAS intervenes again, ad 
infinitum). How bad the CAS failure is depends on the architecture.

That said, I believe Unsafe.getAndAddLong is an intrinsic in Java 8 and 
9 and will, barring any -XX options to the contrary, result in an 
'inline_unsafe_load_store(T_LONG,   LS_xadd);' further resulting in LOCK 
XADDL on X86, so it's a non-issue to begin with for X86 architectures. 
You might be interested in a similar intrinsic for ARMv8 if one isn't 
already available and could be implemented.

- Arcadiy

On 2014-05-22 12:20, Andrew Haley wrote:
> I don't think that word-tearing matters here: all it will do in the
> odd chance that it occurs is cause a retry.



More information about the Concurrency-interest mailing list