What is Memory consistency model?
The contract specifying in what order a core's reads and writes to multiple addresses may be observed by other cores. Examples include sequential consistency, x86 TSO and the weak models of Arm and RISC-V.
Field: Multicore & Synchronization
Japanese name: メモリ一貫性モデル
Why hardware reorders memory operations
High-performance cores do not perform loads and stores strictly in program order. A store is often parked in a store buffer while the core moves on, and loads may be issued early or out of order to hide cache latency. These optimizations are invisible inside a single thread, because the core always forwards its own pending writes and preserves its own results. Another core, however, can see the same operations in a different order. A memory consistency model is the contract stating exactly which of these reorderings may become visible, so programmers and compilers know when synchronization is required.
Sequential consistency, TSO and weak models
Sequential consistency (SC) is the strictest model: all operations appear to occur in one global order that respects each core's program order. x86 uses total store order (TSO), which is nearly as strong: the only visible reordering is a later load to a different address completing before an earlier store, exactly what a FIFO store buffer produces. Arm and RISC-V use weak models that allow loads and stores to different addresses to be reordered in most combinations. Ordering must then be requested explicitly with fence or barrier instructions or with acquire and release operations.
A classic example: the store-buffer test
Let core 0 execute x = 1 then read y, while core 1 executes y = 1 then read x, with x and y initially 0. Under sequential consistency at least one core must read 1. Under TSO both can read 0, because each store may still sit in its own core's store buffer when the other core's load runs. Lock algorithms such as Dekker's and Peterson's fail in exactly this way unless a full fence is placed between the store and the load. On a weak model, even passing data with a flag can fail unless barriers order the accesses.
Consistency vs. cache coherence
Cache coherence is a guarantee about a single address: all cores agree on the order of writes to that location and eventually see the latest value. A consistency model covers ordering across different addresses, such as whether a write to x becomes visible before a later write to y. A system can be fully coherent and still show such reorderings, which is why barriers exist alongside coherence protocols. High-level languages define their own models, such as C11 and C++11 atomics, and compilers translate them into the barrier instructions the hardware model requires.
Try it: questions about Memory consistency model
- AThe cache line size and the number of sets
- BThe kind of transistors used in main-memory DRAM
- CIn what order a core's reads and writes to multiple addresses may be observed by other cores
Show answer and explanation
Answer: C. In what order a core's reads and writes to multiple addresses may be observed by other cores
For performance, CPUs may reorder memory operations, for example by holding writes in a store buffer or performing reads early. They are designed so that results within one core are unchanged, but other cores may observe the operations in a different order. A memory consistency model defines which reorderings can occur and is the contract that lets programmers write correct synchronization.
- AIt is the weakest model, allowing every combination of reordering
- BIt is exactly sequential consistency, allowing no reordering at all
- CIt is a relatively strong model that allows only a later read of a different address to appear before an earlier write
Show answer and explanation
Answer: C. It is a relatively strong model that allows only a later read of a different address to appear before an earlier write
Under TSO, writes stay ordered with writes, reads with reads, and a write after a read stays ordered; only a read of a different address may overtake an earlier write. This model directly reflects the presence of a store buffer. Many programs behave intuitively within these limits, so barriers are needed relatively rarely on x86.
FAQ
What is the difference between cache coherence and memory consistency?
Coherence ensures that all cores see writes to one address in the same order and eventually read the latest value. Consistency defines the order in which accesses to different addresses may be observed by other cores.
What does TSO stand for?
TSO stands for total store order, the memory model used by x86 processors. It allows only a later load to a different address to be observed before an earlier store, an effect of the store buffer.
Why do Arm and RISC-V programs need more memory barriers than x86 programs?
Arm and RISC-V use weak memory models that permit most reorderings of loads and stores to different addresses, so ordering must be requested explicitly. x86 TSO already keeps most orderings, so barriers are needed only in cases such as a store followed by a load to another address.
Books on Multicore & Synchronization Ad
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.
Back to the glossary