← Lessons

quiz vs the machine

Gold1480

Concurrency

Sequential Consistency vs Relaxed

Strong global ordering versus weaker faster memory models.

5 min read · core · beat Gold to climb

Sequential Consistency vs Relaxed

A memory model defines what values a read may return when many threads share memory. The strongest practical model is sequential consistency, while modern hardware and languages also offer relaxed models for speed.

Sequential consistency says the result of any execution is as if all operations from all threads ran in some single total order, and each thread keeps its own program order within that interleaving. It is the model most people imagine by default. It is easy to reason about but expensive, because it forbids many fast reorderings.

Relaxed models loosen these rules. They allow operations to become visible in different orders to different threads, so long as a thread sees its own actions consistently. Atomics may carry an explicit ordering tag:

  • Relaxed Only atomicity, no ordering with other variables.
  • Acquire and release Pair to publish and consume data without a full fence.
  • Sequentially consistent Restores a single global order at higher cost.

The tradeoff is clear. Sequential consistency is simpler to reason about but slower. Relaxed ordering is faster and matches hardware but forces programmers to think carefully about what each thread may observe. Choosing the weakest ordering that is still correct is a core skill in low level concurrency.

Key idea

Sequential consistency gives one intuitive global order at a performance cost, while relaxed models trade that simplicity for speed by allowing threads to observe different orderings.

Check yourself

Answer to earn rating on the learn ladder.

1. What does sequential consistency guarantee?

2. What is the tradeoff of relaxed memory models?