Happens-Before and Cross-Thread Visibility
Use program order and a synchronization edge to prove when a later read can rely on an earlier write.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Temporal order and semantic order are separate
In a language with a happens-before relation, orders within threads and designated synchronization edges combine transitively. Suppose a producer writes a result, then publishes completion under a lock. A consumer takes the corresponding lock before reading the result. If its acquire follows the producer’s release in the required synchronization order, the result write happens before the later read. A timestamp comparison alone is not that language-level proof.
Draw the whole path through each synchronization point
The proof has a producer-local edge to publication, a cross-thread edge, and a consumer-local edge to use. Removing one can leave otherwise ordinary accesses unordered. Model visibility separately from whether a thread is eventually scheduled. Acquire and release show one way to establish the cross-thread edge. Data races describe the consequence of conflicting accesses lacking an appropriate order.[1][2]