Correct? It depends on the memory consistency model.
Coherence vs. Consistency
Coherence
Consistency
Scope
A single address
All addresses
Question
What values can reads of flag return?
Which orderings of flaganddata can threads observe: which final states are legal?
A sequential ISA only promises each processor sees its own operations in program order
It says nothing about when stores to different addresses become visible to other processors
Sequential Consistency (SC)
Lamport: "the result of any execution is the same as if the operations of all the processors were executed in some sequential order, and the operations of each individual processor appear in the order specified by the program."
= an arbitrary order-preserving interleaving, as if all processors used one memory through a switch, one access at a time
SC: whichever store comes first in the interleaving makes the other load see 1
TSO: each store sits in its store buffer; each load runs ahead and reads 0 from memory; the buffers drain later
Check Your Understanding
1. State the difference between coherence and a consistency model.
Coherence: legal values for reads and writes to a single address. Consistency: ordering and visibility rules across all addresses and threads.
2. Why can the litmus test give (0, 0) under TSO but not SC?
Under TSO each store waits in its local buffer while the later load to a different address reads memory early, so both loads can see 0 before either store drains.
Weak Memory Models and Fences
Strong models: easy to program, need slow execution or speculative hardware
Weak models: fewer guarantees, simpler fast hardware; tricky even for experts
Restore order with fences:
Producer: Consumer:
sw xdata, (xdatap) spin: lw xflag, (xflagp)
li xflag, 1 beqz xflag, spin
fence w, w fence r, r
sw xflag, (xflagp) lw xdata, (xdatap)
fence w, w: data visible before flag · fence r, r: flag read before data
Ordering Rules
$X \to Y$: X must be globally visible before Y
Model
R→R
R→W
W→R
W→W
SC
✅
✅
✅
✅
TSO
✅
✅
❌
✅
PSO
✅
✅
❌
❌
WO / Alpha / RMO / PowerPC
❌
❌
❌
❌
Un-fenced producer-consumer needs only W→W and R→R, so it already works on TSO (x86)
Release Consistency (RC)
Basis of ARM and RISC-V weak models: relaxes all four ordinary orders; adds acquire $S_A$ and release $S_R$
A thread sees its own writes early, but once a store is visible to one other thread, it's visible to all
Shared cluster buffers let a neighbor see a write before distant cores do
Industry consensus: non-multi-copy-atomic is too weak and error-prone for general-purpose CPUs
Check Your Understanding
1. Which ordering does TSO relax vs. SC, and why does un-fenced producer-consumer still work on TSO?
Only W→R. The producer needs W→W and the consumer needs R→R, both of which TSO keeps.
2. What distinguishes multi-copy atomic from non-multi-copy atomic models?
Multi-copy atomic: once a store is visible to any other thread it's visible to all. Non-multi-copy atomic: one remote core can see a store before others (e.g., via shared cluster buffers).
← → / space to move · A to reveal answers · F fullscreen