[concurrency-interest] AtomicXXX.lazySet and happens-before reasoning

Doug Lea dl at cs.oswego.edu
Fri Sep 30 12:41:58 EDT 2011


On 09/30/11 11:18, Ruslan Cheremin wrote:
> I still do not catch it. As far as I see we have 2 question about the code:

These are still good questions, because they have no direct answers in JLS.
But because they don't, you need to use other existing information to decode.
One more try:

>
> 1) Will lazySet write actually happens in some finite time?

The most you can say from the spec is that it will be written
no later than at the point that the process must write anything
else in the Synchronization Order, if such a point exists.
However, independently of the spec, we know that so long as
any process makes progress,  only a finite number of writes
can be delayed. So, yes.

> 2) If it happens (== we see spin-wait loop finished) -- does it mean, what
> all writes preceeding lazySet are also done, commited, _and visible_ to
> thread 2, which finished spin-wait loop?

Yes, although technically, you cannot show this by reference
to the Synchronization Order in the current JLS. A fully
integrated account would be along the lines of that for
the (non-existent) order{Writes,Accesses} Fences in
http://gee.cs.oswego.edu/dl/jsr166/dist/docs/java/util/concurrent/atomic/Fences.html

-Doug


More information about the Concurrency-interest mailing list