Every execution has a synchronization order. A synchronization order is a total order over all of the synchronization actions of an execution. For each thread t, the synchronization order of the synchronization actions (§17.4.2) in t is consistent with the program order (§17.4.3) of t.
Synchronization actions induce the synchronized-with relation on actions, defined as follows:
-
An unlock action on monitor m synchronizes-with all subsequent lock actions on m (where "subsequent" is defined according to the synchronization order).
-
A write to a volatile variable v (§8.3.1.4) synchronizes-with all subsequent reads of v by any thread (where "subsequent" is defined according to the synchronization order).
-
An action that starts a thread synchronizes-with the first action in the thread it starts.
-
The write of the default value (zero,
false, ornull) to each variable synchronizes-with the first action in every thread.Although it may seem a little strange to write a default value to a variable before the object containing the variable is allocated, conceptually every object is created at the start of the program with its default initialized values.
-
The final action in a thread
T1synchronizes-with any action in another threadT2that detects thatT1has terminated.T2may accomplish this by callingT1.isAlive()orT1.join(). -
If thread
T1interrupts threadT2, the interrupt byT1synchronizes-with any point where any other thread (includingT2) determines thatT2has been interrupted (by having anInterruptedExceptionthrown or by invokingThread.interruptedorThread.isInterrupted).
The source of a synchronizes-with edge is called a release, and the destination is called an acquire.