Weak Memory Models
Weak memory models specify which cross-thread observations are allowed. Release and acquire can justify ordinary data publication through a precise happens-before chain.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 3
- Reading time
- 1 min
In this article3 chapters
Per-thread order and cross-thread order
A shared-memory model constrains complete executions. C11 distinguishes order within a thread, the per-location modification order of atomic writes, and synchronization between threads. Happens-before combines specified order and synchronization edges transitively. Two conflicting accesses, at least one a write and at least one non-atomic, can constitute a data race if unordered by happens-before. The standard’s race rule is part of the semantics of the source program.
An interleaving proof under sequential consistency supplies a reference model. With acquire and release, an ordering proof instead tracks the specific publication and observation that establish synchronization.
A safe publication argument
A producer writes ordinary data and publishes a flag with a release store. A consumer first loads the flag with acquire and reads the data only after observing the producer’s release value. In this simple direct read-from case the chain is
\[ W_d\xrightarrow{\mathrm{sb}}W_f^{\mathrm{rel}} \xrightarrow{\mathrm{sw}}R_f^{\mathrm{acq}} \xrightarrow{\mathrm{sb}}R_d . \]
The labels mean sequenced-before and synchronizes-with. Transitivity orders the write and read of the ordinary data. An atomic flag alone does not imply the middle edge. The publication proof therefore states exactly which value the consumer can use and excludes concurrent overwriting of the published data.
An architecture has its own execution model
Arm ordering is expressed through architecture-specific events, dependencies and ordering instructions. A compiler must implement the source operations so that target executions satisfy the source model for the program in question. Cache coherence concerns behavior for individual locations, while memory consistency also constrains their relations. See coherence protocols, verified compilation, and ownership-based proofs of sharing in concurrent separation logic.[1][2]