[concurrency-interest] Unsynchronized lazy conditions

Aleksey Shipilev 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...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20180531/d658b65f/attachment-0001.sig>

More information about the Concurrency-interest mailing list