[concurrency-interest] Happens Before guarantee in case of unsafe.putOrderedObject and corresponding nomal read of a variable

Doug Lea dl at cs.oswego.edu
Fri Sep 5 07:29:21 EDT 2014


On 09/05/2014 07:26 AM, Andrew Haley wrote:
> On 09/05/2014 12:07 PM, Doug Lea wrote:
>> On 09/04/2014 10:17 PM, vikas wrote:
>>> I just wanted  to know if there is any kind of synchronization/happens before
>>> guarantees with
>>> unsafe.putOrderedObject(data) and normal read of that particular data.
>>
>> In general, not. In C++/C11 terms, putOrderedObject provides
>> a release-mode write, that must be paired with an acquire-mode
>> read, which you can do via getObjectVolatile if not already volatile.
>> There are a few special cases where you do not need this because
>> of some other dominating volatile reads/writes, but they are not common.
>
> While we have this particular box open, do you know why
> AtomicIntegerFieldUpdater.putOrderedInt() uses Unsafe.putOrderedInt() ?
>
> That one always baffles me.  I would have thought it was just a store.
>

Because the underlying field must be volatile, at implementation level,
the VM would otherwise generate the heavier full volatile store.

-Doug




More information about the Concurrency-interest mailing list