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

Andrew Haley aph at redhat.com
Fri Sep 5 07:26:33 EDT 2014


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.

Andrew.



More information about the Concurrency-interest mailing list