[concurrency-interest] Unsynchronized lazy conditions
shade at redhat.com
Thu May 31 06:27:35 EDT 2018
On 05/31/2018 12:19 PM, Alex Otenko wrote:
> I don’t get this advice. Do the simple thing, declare it volatile. Optimize further (learning
> curve + operational subtleties) when that is not fast enough.
My original reply was about that: what OP has does appear to work.
It does not mean OP should use it, though, instead of doing the idiomatic shape: do AtomicX, gain
CAS capability, have fast-path test, on slow-path do CAS to perform the action exactly once.
Optimize from that, if you prove that idiom is not working for you.
> (VH.get cannot be different from volatile load on x86, can it?..)
Of course it can, it is the magic of VarHandles: use-site, not declaration-site memory semantics. So
you can have volatile field and do non-volatile read over it, or you can have non-volatile field and
do volatile read or CAS over it.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the Concurrency-interest