Unit content
Memory consistency and acquire-release synchronization
Cache coherence answers how copies of one memory location are reconciled. A memory consistency model answers a broader question: which orderings of loads and stores may concurrent threads observe?
Compilers and processors can reorder independent memory operations for performance. Without synchronization, another thread is not generally entitled to observe ordinary writes in source-code order.
Consider a producer publishing data:
data = 42
ready = true
and a consumer:
if ready:
use(data)
Making only ready atomic is not enough unless its ordering semantics also connect the preceding write to data with the consumer's later read.
A release operation publishes earlier memory effects before the release becomes visible. An acquire operation that observes that release prevents later operations from moving before it. Together they create a synchronization relation: writes before the release become visible to reads after the matching acquire according to the language's memory model.
Stronger ordering such as sequential consistency is easier to reason about but can impose more constraints. Weaker orders permit more optimization but require more precise synchronization reasoning.
Correct concurrent code should rely on the memory model and synchronization primitives of its language, not on accidental ordering observed on one processor.