The happens-before relation orders evaluations and events so concurrent execution can be analyzed as a coherent whole. In C terms, F happens before E, written F → E; the relation is observed after the events occur. section 19.1
TAKEAWAY
- Sequenced-before evaluations in one thread also establish a happens-before relation. section 19.1
- Synchronization between threads comes from atomic operations or certain C library calls. section 19.1
- Atomic modifications have a modification order consistent with the sequenced-before relations of threads accessing that atomic object. section 19.1
From one thread to two
If an assignment to command[0] is sequenced before a switch statement, every case is executed after that assignment, or is perceived as happening later; passing command to nested calls therefore provides the modified value. Across threads, an atomic write followed by another thread's read of the written value supplies synchronization. section 19.1 section 19.1
Figure 19.1. Two threads that synchronize via an atomic. The circles present the modifications of object x. The bars below the threads represent information about the state of A, and those above represent information about the state of B.
A figure traces two threads synchronized through atomic object x, showing its modifications and each thread's view of state. section 19.0




