What is Total store order (TSO)?
The x86 memory consistency model. It allows only a later read of a different address to overtake an earlier write, reflecting the presence of a store buffer.
Japanese name: TSO(トータルストアオーダー)
The x86 memory consistency model. It allows only a later read of a different address to overtake an earlier write, reflecting the presence of a store buffer.
Japanese name: TSO(トータルストアオーダー)
TSO (total store order) is a memory consistency model that describes behavior nearly identical to the x86 memory model. The order of reads with reads, writes with writes, and a write after a read is preserved; the only reordering other cores may observe is a read of a different address overtaking an earlier write. In addition, all writes become visible to other cores in one single order. The name 'total store order' refers to this single overall order of stores.
TSO directly models a design in which each core has a first-in, first-out store buffer. The core puts writes into the buffer and keeps executing, draining them to the cache later. Meanwhile later reads can fetch values from the cache, so the write appears to have been overtaken by the read. A core's own reads can receive the value of its own buffered writes early (store-to-load forwarding). Because the buffer drains in order, writes stay ordered with respect to one another.
Sequential consistency, a stronger guarantee than TSO, makes the operations of all cores appear in a single sequence that preserves each core's program order. Under TSO, with x and y both 0, if core 1 writes x = 1 and then reads y while core 2 writes y = 1 and then reads x, both can read 0, which sequential consistency forbids. Weaker models such as Arm and RISC-V (RVWMO), on the other hand, also allow writes to be reordered with writes and reads with reads, so passing data between cores needs more barriers or acquire/release instructions than under TSO.
Under TSO, much synchronization, such as handing off data with a flag, works intuitively without special instructions. A barrier is needed when the order of a write followed by a read of a different address must be kept, as in mutual exclusion like Dekker's algorithm. On x86, the MFENCE instruction, LOCK-prefixed instructions and XCHG with a memory operand act as barriers that drain the store buffer. With C11 or C++11 atomics, acquire and release loads and stores compile to ordinary instructions, and typically only sequentially consistent stores use a barrier or XCHG.
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.
Under sequential consistency every read and write appears in program order. TSO allows only one exception: a read of a different address that follows a write may appear to happen before that write. This happens because the later read proceeds while the write is still waiting in the store buffer.
The x86 memory model is defined in prose in the Intel and AMD manuals and is known to be essentially TSO; its formal definition is called x86-TSO. The name TSO itself comes from a model defined in the SPARC architecture.
Sometimes. Algorithms that only work if a write is ordered before a later read of a different address, such as Dekker's algorithm, need MFENCE or a LOCK-prefixed instruction on x86. In high-level languages, using atomics lets the compiler emit the necessary instructions.
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.