rust · concurrency

Memory ordering in practice (not the spec)

2026-04-202 min readrust

The Rust memory model docs are precise and cold. On a hot path you need a smaller question: what synchronization does this atomic actually guarantee?

This is part three of the lock-free series — after ABA/tagging and reclamation.

The three you use daily

Relaxed
owns: atomicity only
counters, statisticsno cross-thread ordering
Cheapest. Don't use for publishing a pointer others will dereference.
Acquire / Release
owns: publish-subscribe
Release store after writing dataAcquire load before reading it
The default pattern for lock-free handoff.
SeqCst
owns: global order
rare in app codedebugging heisenbugs
Strongest, slowest. Reach for it when weaker orders fail and you need proof.

A handoff that works

handoff.rs
1data.write(payload);2ready.store(true, Ordering::Release);34if ready.load(Ordering::Acquire) {5    let v = data.read();6}
🦀
Ferris' hot tip

If you're mixing atomics and mutexes on the same data, stop — pick one story. Hybrid "mostly lock-free" code is where ordering bugs hide for months.

When to read the spec

Before you ship a general-purpose concurrent crate. Before you argue on Twitter. For application queues and metrics, Acquire/Release + crossbeam gets you home.

Comments
Loading comments…