Definition
Memory Model
A memory model specifies which values a thread may observe from shared memory and which reorderings of loads and stores are allowed.
Equivalently, it defines the relation between a program’s local order and the global execution order seen by all threads.
Purpose
The hardware may reorder instructions for performance. The memory model states which reorderings remain visible to the programmer.
The programming language exposes this contract through atomic operations and memory-order annotations.
Common Models
Main levels
- Sequentially consistent memory: one global order, preserving program order.
- Release-acquire memory: order is enforced only around release and acquire operations.
- Relaxed memory: minimal ordering; the programmer must not rely on implicit visibility.
Consequence
Correctness depends on the model
A concurrent algorithm that is correct under one memory model may fail under another. Shared-memory code must therefore be designed with the target model in mind.