title: How do threaded systems cope with shared data being being cached by different cpus?
body: <p>I'm coming largely from a c++ background, but I think this question applies to threading in any language. Here's the scenario:</p>
  
  <ol>
  <li><p>We have two threads (ThreadA and ThreadB), and a value x in shared memory</p></li>
  <li><p>Assume that access to x is appropriately controlled by a mutex (or other suitable synchronization control)</p></li>
  <li><p>If the threads happen to run on different processors, what happens if ThreadA performs a write operation, but its processor places the result in its L2 cache rather than the main memory? Then, if ThreadB tries to read the value, will it not just look in its own L1/L2 cache / main memory and then work with whatever old value was there?</p></li>
  </ol>
  
  <p>If that's not the case, then how is this issue managed?</p>
  
  <p>If that is the case, then what can be done about it?</p>