i = 1
always happens-beforev = 2
True. By JLS section 17.4.5,
If x and y are actions of the same thread and x comes before y in program order, then hb(x, y).
v = 2
happens-beforevDst = v
in JMM only if it’s actually happens before in timei = 1
happens-beforeiDst = i
in JMM (andiDst
will be predictably assigned1
) ifv = 2
actually happens beforevDst = v
in time
False. The happens-before order does not make guarantees about things happening before each other in physical time. From the same section of the JLS,
It should be noted that the presence of a happens-before relationship between two actions does not necessarily imply that they have to take place in that order in an implementation. If the reordering produces results consistent with a legal execution, it is not illegal.
It is, however, guaranteed that v = 2
happens-before vDst = v
and i = 1
happens-before iDst = i
if v = 2
comes before vDst = v
in the synchronization order, a total order over the synchronization actions of an execution that is often mistaken for the real-time order.
- Otherwise order between
i = 1
andiDst = i
is undefined and resulting value ofiDst
is undefined as well
This is the case if vDst = v
comes before v = 2
in the synchronization order, but actual time doesn’t come into it.