← [ ABORT TO HUD ]
SEQ. 1
SEQ. 2
Hardware Memory Models & Atomic Ordering Semantics
The Illusion of Sequential Consistency
Modern CPUs do not execute instructions strictly in code order. Out-of-Order (OoO) execution engines, store buffers, and invalidation queues reorder loads and stores to maximize pipeline utilization. While x86 enforces Total Store Order (TSO) (loads are not reordered with older loads, stores are not reordered with older stores), ARM64 and Apple Silicon use a weakly ordered memory model where almost any access can be reordered unless constrained by memory fences.
The Five Rust Atomic Orderings
| Ordering | Guarantees | Hardware Mapping (x86) | Hardware Mapping (ARM64) |
|---|---|---|---|
Relaxed | Atomicity only. Zero synchronization or ordering with other variables. | Plain MOV | LDR / STR |
Acquire | No subsequent reads or writes can be reordered BEFORE this load. | Plain MOV (free!) | LDAR (Load-Acquire) |
Release | No prior reads or writes can be reordered AFTER this store. | Plain MOV (free!) | STLR (Store-Release) |
AcqRel | Combined Acquire (for load) and Release (for store) in Read-Modify-Write. | LOCK CMPXCHG | LDAXR / STLXR |
SeqCst | Total global order seen by all threads across all variables. | MFENCE / LOCK MOV | DMB ISH |
The Acquire-Release Synchronization Pattern
To pass data safely between threads without a mutex, pair a Release store with an Acquire load:
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
static DATA_PAYLOAD: AtomicUsize = AtomicUsize::new(0);
static READY_FLAG: AtomicBool = AtomicBool::new(false);
// Thread 1: Producer
DATA_PAYLOAD.store(42, Ordering::Relaxed);
READY_FLAG.store(true, Ordering::Release); // Releases prior writes to other threads
// Thread 2: Consumer
if READY_FLAG.load(Ordering::Acquire) { // Acquires all writes released by Thread 1
let val = DATA_PAYLOAD.load(Ordering::Relaxed);
assert_eq!(val, 42); // Guaranteed to see 42!
}
⌨ HANDS-ON LABVerify Atomic Memory Orderings with Loom
⭐ +160 XPRun exhaustive permutation model checking under Loom to detect memory ordering race conditions on weakly ordered hardware.
1Run Loom model checker on lock-free Acquire-Release message passing.
2Disassemble atomic store on ARM64 to verify hardware STLR instruction generation.
OBJECTIVE 1 / 2 — type "hint" if stuck
SYNAPSE VERIFICATION
QUERY 1 // 1
On x86_64 processors, what hardware assembly instruction does an Atomic::load(Ordering::Acquire) compile down to?
A standard plain 'mov' instruction with zero hardware penalty
A costly 'mfence' instruction that halts the CPU pipeline
A 'lock cmpxchg' instruction requiring bus synchronization
A software trap into the operating system kernel