Semantics of finite fields in JMM

Here [ http://docs.oracle.com/javase/specs/jls/se7/html/jls-17.html#jls-17.5 * [1 ]

He says:

To write w, freeze f, act a (unread final field), read r1 of the final field, frozen f, and read r2 such that hb (w, f), hb (f, a), mc (a, r1 ) and expansion (r1, r2), then in determining which values ​​can be seen through r2, consider hb (w, r2). (This happens - before the ordering does not transit close to other cases - before the orders.)

What do they want to say here? I understand that r2 is just reading the final value of the field that was read by r1, so it's pretty clear that hb (w, r2), because r1 is reading the correct version of that variable, because the value was frozen at f. Or do they mean something else? Very deep? And what are they trying to say that these hb orders are not "transitively closed" with different hb settings?

+3


source to share


1 answer


The lonely fact that it r1

reads the meaning written w

does not even mean that hb(w, r1)

, let alone hb(w, r2)

. This is the opposite: if there is a relationship between w

and r1

, then JMM guarantees which value will be observed; otherwise there is no guarantee. If r1

observing the value from w

, it is just a match and does not throw hoc, causing communication between events.

The best way to imagine a poignant example of when it matters is to use secure publishing during a data race. A reference to is String

written to a non-volatile field without synchronization, and this field is then dereferenced from another stream. If a thread is watching String

(there is no guarantee that it will), there is a guarantee that the thread will see it String

in a consistent state.

Without special provision for an emergency event, before which only the exact event described in your quote is considered, there would be no guarantee that it String

would be kept intact.



what are they trying to say that these hb orders are not "transitively closed" with different hb settings?

Typically, hb(a,b)

and hb(b,c)

mean hb(a,c)

, but this transitivity does not apply to special cases - prior to the existence of an unresponsive pitch. These special events used to have their own namespace.

+2


source







All Articles