6. ConcurrencyMemory models
Memory models
A memory model is the set of rules for what one thread is allowed to see when another thread writes to memory. You’d expect writes to appear instantly and in program order, but compilers and CPUs reorder and buffer memory operations for speed; a core may hold a write in a store buffer while it reads other values. A single thread can never tell, but across threads this produces results that look impossible. The language (C++, Java, Go) and the hardware each define which orderings are guaranteed. Locks and atomics with acquire and release semantics are how you ask for order: whatever a thread wrote before a release is visible to a thread that acquires it.
In this lesson: A store-buffer sim where an “impossible” result happens.