title: Will Peterson's solution work correctly on modern CPU architectures?
body: <p>I am studying operating systems from <a href="https://rads.stackoverflow.com/amzn/click/com/0470128720" rel="noreferrer" rel="nofollow noreferrer">Operating System Concepts</a> by Silberschatz, Galvin, and Gagne. </p>
  
  <p>On page 229, the book states this about <a href="http://en.wikipedia.org/wiki/Peterson%27s_algorithm" rel="noreferrer">Petersons Solution</a> :</p>
  
  <blockquote>
    <p>Because of the way modern computer architectures perform basic machine
    language instructions, such as load and store, there are no guarantees
    that Peterson's solution will work correctly on such architectures.</p>
  </blockquote>
  
  <p>I looked this up on <a href="http://en.wikipedia.org/wiki/Peterson%27s_algorithm" rel="noreferrer">Wikipedia</a> and found this which appears to be the closest to an explanation :</p>
  
  <blockquote>
    <p>Most modern CPUs reorder memory accesses to improve execution efficiency. Such processors invariably give some way to force ordering in a stream of memory accesses, typically through a memory barrier instruction. Implementation of Peterson's and related algorithms on processors which reorder memory accesses generally requires use of such operations to work correctly to keep sequential operations from happening in an incorrect order. Note that reordering of memory accesses can happen even on processors that don't reorder instructions</p>
  </blockquote>
  
  <p>I am having trouble understanding what this means or if this is even the answer. </p>
  
  <p>So, why is Peterson's solution not guaranteed to work on modern architectures ?</p>