Lukas' Notes

memory-models

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

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.