...
Consider two threads that are executing some statements:
...
Thread 1
...
Statement 1
...
(statement does not use a volatile
variable)
...
Statement 2
...
(statement does not use a volatile
variable)
...
Statement 3
...
(statement is a write to a volatile
variable v)
...
...
...
Thread 2
...
...
...
Statement 4
...
Thread 1 and Thread 2 have a happens-before relationship such that Thread 2 does not start before Thread 1 finishes. This is established by the semantics of volatile
accesses. Sequential consistency of volatile
accesses provides certain visibility and reordering guarantees:
...