title: Volatile fence demo?
body: <p><em>Im trying to see how the fence is applied.</em></p>
  
  <p>I have this code (which  Blocks indefinitely): </p>
  
  <pre><code>static void Main()
  {
      bool complete = false;
      var t = new Thread(() =&gt; {
          bool toggle = false;
          while(!complete) toggle = !toggle;
      });
      t.Start();
      Thread.Sleep(1000);
      complete = true;
      t.Join(); // Blocks indefinitely
  }
  </code></pre>
  
  <p>Writing <code>volatile bool _complete;</code> solve the issue .</p>
  
  <p>Acquire fence : </p>
  
  <blockquote>
    <p>An acquire-fence prevents other reads/writes from being moved <strong>before</strong> the fence;</p>
  </blockquote>
  
  <p>But if I illustrate it using an arrow <code>↓</code> <em>( Think of the arrowhead as pushing everything away.)</em></p>
  
  <p>so now -  the code can look like : </p>
  
  <pre><code> var t = new Thread(() =&gt; {
              bool toggle = false;
              while( !complete ) 
                      ↓↓↓↓↓↓↓     // instructions can't go up before this fence.  
                 {
                   toggle = !toggle;
                  }
          });
  </code></pre>
  
  <p>I don't understand how the illustrated drawing represent a solution for solving this issue.</p>
  
  <p>I do know that <code>while(!complete)</code> now reads the real value. but how is it related to <code>complete = true;</code> location to the fence ?</p>