Compilers, CPU, Memory, Cache Coherency, Atomicity, Syncronization and ordering Are Not Black Magic but The Mix Is Close Enough
Introduction: The Illusion of Sequential Execution
When you write code, you naturally think in terms of sequential execution: instruction A happens, then instruction B, then instruction C. This mental model works perfectly—until you start writing concurrent code or working with hardware. Then you discover that modern CPUs, compilers, and memory systems conspire to execute your code in ways you never imagined.
The truth is that sequential consistency is largely an illusion maintained by your compiler and CPU to make programming tractable. But when multiple cores or threads are involved, that illusion breaks down in spectacular and subtle ways.