[jmm-dev] weakCompareAndSet memory semantics
Aleksey Shipilev
aleksey.shipilev at oracle.com
Wed Apr 20 12:58:41 UTC 2016
On 04/20/2016 02:56 PM, Doug Lea wrote:
> On 04/20/2016 06:03 AM, Andrew Haley wrote:
>> On 20/04/16 10:55, Aleksey Shipilev wrote:
>>> I wonder if that was the intended use for weakCAS in C++11, and if so,
>>> shouldn't we re-spec weakCAS in Java to have volatile/seq_cst memory
>>> effects?
>>
>> Probably. Or, at least, we want a weakCompareAndSet which is
>> sequentially
>> consistent. As a general principle: we have an opportunity to make
>> Java's
>> operators consistent with those of C++, and we shouldn't mess that up.
>>
>
> Yes. I'm not sure what happened to method weakCompareAndSetVolatile
> that was in early sketches but disappeared (probably my fault) without
> me or anyone else noticing. Aleksey and/or Paul: Can you add this?
Thanks, it's not too late to add.
This raises the naming questions, which will be cast in stone in
VarHandles public API:
a)
weakCompareAndSet (relaxed!)
weakCompareAndSetAcquire
weakCompareAndSetRelease
weakCompareAndSetVolatile
(This provides the symmetry against j.u.c, and does not require re-spec,
just adding a new method)
...or
b)
weakCompareAndSet (volatile!)
weakCompareAndSetAcquire
weakCompareAndSetRelease
weakCompareAndSetRelaxed/Plain
(This provides the symmetry against default mem_ord in C++, and also new
CompareAndExchange{epsilon, Acquire, Release}).
Thanks,
-Aleksey
More information about the jmm-dev
mailing list