title: Hardware model behind read/write behavior done by threads in C++
body: <p>I'm trying to understand what happens behind the scenes when reading and writing global variables by multiple threads on a multi-CPU, multi-core hardware.</p>
  
  <p>Let's say we have 3 threads in a process and 1 global variable and that thread 1 writes a value to it and threads 2 and 3 read that value. It may happen that thread 2 picks up the latest value while thread 3 doesn't. I'm wondering how can that happen? My first guess would be that thread 1 updates the value in the CPU cache but doesn't write to main memory. Then let's say that thread 2 is scheduled to run on exactly the same processor as thread 1 was running on so it can pick up the latest value. At the same time thread 3 is scheduled to run on a different CPU and reads an old value as it doesn't have access to the cache with the updated value.</p>
  
  <p>My question is, is this explanation is correct?</p>