4.1.26 · D1Computer Architecture (Deep)

Foundations — Memory models — sequential consistency, TSO, relaxed

1,838 words8 min readBack to topic

This page assumes you have seen nothing. We build every word the parent note uses, one brick at a time, before you ever meet SC, TSO, or a fence.


1. A "thread" — the worker who follows a to-do list

Picture two people, each holding their own paper list, both allowed to write into and read from one shared whiteboard in the middle of the room.


2. Memory locations x, y — labelled boxes on the whiteboard

Think of the whiteboard as a grid of labelled boxes. x and y are two different boxes.


3. Store and Load — the only two verbs


4. Program order — the order written on your list


5. Reordering — the box order getting shuffled

Read as " comes first in program order; can overtake it?"


6. The store buffer — why Store→Load can happen


7. Interleaving and total order — one shared timeline


8. Coherence — the one rule that's always on

See Cache Coherence (MESI) for how hardware enforces this per box.


9. Fence / barrier — the "wait here" wall


10. Litmus test — the smallest experiment


How these feed the topic

Thread = one to-do list

Store and Load = the two verbs

Memory box x y = shared whiteboard

Program order = written order

Reordering = four pairs

Store buffer = private wait list

Total order = one timeline

Coherence = per box always

Litmus test = smallest experiment

Fence = wait here wall

Memory Models SC TSO Relaxed

Everything on the left is a foundation; they all funnel into the parent topic Memory Models. Prerequisites Store Buffers and Out-of-Order Execution and Happens-before and Synchronizes-with extend the store-buffer and total-order ideas.


Equipment checklist

Self-test: cover the right side and answer aloud.

What is a thread, in one picture?
One worker reading a private to-do list, top to bottom, sharing a whiteboard with others.
What is the difference between a store and a load?
Store writes a value into a shared box; load reads a box's current value into a private register.
What is program order?
The top-to-bottom order of instructions as written in a single thread's source.
Why is program order NOT what other threads observe?
Hardware and compilers may let a later operation take effect before an earlier one (reordering).
How many reorder pairs exist and why?
Four — Store/Load × Store/Load, since each of two ops is one of two verbs.
What does a store buffer do?
Holds a store privately so the core moves on before the write reaches shared memory, enabling Store→Load reordering.
What is store forwarding?
A core can read its own pending buffered stores, so it never sees its own writes as stale.
What is a total order / interleaving?
One global timeline placing every thread's operations in a single sequence, keeping each thread's internal order.
What does coherence guarantee, and what does it NOT?
Guarantees a single agreed order of writes to ONE box; says nothing about ordering across different boxes.
What does a fence like MFENCE do?
Forces ordering — drains the store buffer so earlier stores become visible before later operations run.
What is a litmus test?
The minimal multi-thread program exposing one specific reordering, used to define which outcomes a model allows.