computer-architecture memory-models
Definition
Relaxed Memory Model
A relaxed memory model allows the compiler or CPU to reorder loads and stores as long as the reordering preserves single-threaded behaviour.
Unlike sequentially consistent memory, a relaxed model does not require a single global order that respects all program orders.
Meaning
Performance model
Relaxed memory exposes more hardware optimisations: out-of-order execution, write buffers, cache effects, and compiler reordering.
The programmer must not assume that a statement appearing earlier in source code is observed earlier by other threads.
Consequence
Shared-memory bugs
A protocol that relies on implicit ordering can fail under relaxed memory. In particular, a producer-consumer pattern using a plain flag is not safe unless the flag carries release-acquire ordering.
Relation
Three levels