Happens-before relation
A happens-before relation is a partial ordering between events that establishes when one causally precedes another for reasoning about execution and effects.
C++ Concurrency in Action, Second Edition
A C++ memory-model ordering relation between evaluations that establishes when one precedes another, including across threads.
- How it is used
- Establishes whether writes to shared non-atomic data precede reads in another thread.
- How deep it goes
- Derives ordering through sequencing, synchronization, and transitivity, then applies it to mutexes and a lock-free stack.
- Examples
- Traces an atomic ready flag, unspecified function-argument order, a spinlock, and lock-free stack publication.
- What you can do after
- Diagnose/debug with it by tracing whether synchronization orders each non-atomic write before a cross-thread read.
Read how C++ Concurrency in Action, Second Edition explains happens-before relation →
Modern C
A happened-before relation is an ordering relation that establishes that one evaluation or event precedes another for purposes of reasoning about concurrent execution.
- How it is used
- Provides the ordering needed to reason about correctness and performance across concurrent evaluations.
- How deep it goes
- Defines the relation, connects it to sequenced-before and synchronization, and stops short of dependency-ordered-before details.
- Examples
- Uses a command assignment before a switch and a two-thread atomic object with ordered modifications.
- What you can do after
- Evaluate concurrent execution by identifying sequenced-before relationships and synchronization events.
Modern C, Third Edition
A happened-before relation is a partial ordering that establishes that one event in a concurrent execution precedes another for purposes of reasoning about their effects.
- How it is used
- Supports reasoning about correctness, visibility, and timing between concurrent threads.
- How deep it goes
- Defines the relation, derives it from sequencing and synchronization, and stops short of exhaustive memory-model details.
- Examples
- Uses an atomic unsigned variable, cross-thread increments and assignments, reads, and a modification-order diagram.
- What you can do after
- Evaluate/understand concurrent behavior by identifying sequencing and synchronization that establish event ordering.
Read how Modern C, Third Edition explains happens-before relation →
100 Go Mistakes and How to Avoid Them
A happens-before relationship is a formal ordering relation in which one concurrent operation is guaranteed to occur before another for synchronization and memory-visibility purposes.
- How it is used
- Uses ordering guarantees to prevent data races and make concurrent reads observe preceding writes.
- How deep it goes
- Explains program order, goroutine and channel guarantees, transitivity, and WaitGroup misuse, but does not develop memory-fence internals.
- Examples
- Uses shared-variable reads and writes, buffered and unbuffered channel snippets, and a WaitGroup loop with misplaced Add.
- What you can do after
- Diagnose data races and premature synchronization, then choose channel or WaitGroup ordering that establishes the required relationship.
Read how 100 Go Mistakes and How to Avoid Them explains happens-before relation →
Think Distributed Systems
The happened-before relationship is a causal ordering relation in which one distributed-system event precedes another through local execution and message communication.
- How it is used
- Frames distributed events in terms of causal order rather than relying only on physical time.
- How deep it goes
- Defines local, message-based, transitive, and concurrent ordering, then connects it to logical clocks.
- Examples
- Uses local events, message send and receive pairs, Lamport clocks, Kafka partition offsets, and etcd sequence numbers.
- What you can do after
- Evaluate whether distributed events may be causally ordered or concurrent, and apply logical timestamps to represent that order.
Read how Think Distributed Systems explains happens-before relation →
Related concepts
- synchronizes-with relationproduced by · A synchronizes-with relation is an inter-thread ordering relationship in which a synchronization operation establishes visibility of effects from one thread to another.
- thread-aware memory modelpart of · A programming-language memory model that defines how operations on memory behave and become visible across threads.
- sequenced-before relationhas part · The sequenced-before relation is an ordering relation between evaluations within a single thread, as determined by the programming language’s execution rules.
- synchronizationproduced by · Synchronization coordinates operations, events, clocks, data, or states to establish required timing, ordering, visibility, or consistency relationships.
- memory barrierproduced by · A memory barrier is a synchronization operation that constrains the ordering or visibility of memory accesses across concurrent execution.
- inter-thread orderingproduced by · Inter-thread ordering is a defined precedence relationship between accesses performed by separate threads.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




