title: understanding of Volatile.Read/Write
body: <p>I'm trying to understand the C# Volatile class.</p>
  
  <p>As i read:</p>
  
  <ul>
  <li><p>The <code>Volatile.Write</code> method forces the value in location to be written
  to at the point of the call. In addition, any earlier program-order
  loads and stores must occur before the call to Volatile.Write.</p></li>
  <li><p>The <code>Volatile.Read</code> method forces the value in location to be read from
  at the point of the call. In addition, any later program-order loads
  and stores must occur after the call to Volatile.Read.</p></li>
  </ul>
  
  <p>Is that means the in the case of:</p>
  
  <pre><code>internal sealed class ThreadsSharingData {    
      private Int32 m_flag = 0;
      private Int32 m_value = 0;
      // This method is executed by one thread
      public void Thread1() {        
          // Note: 5 must be written to m_value before 1 is written to m_flag
          m_value = 5;
          Volatile.Write(ref m_flag, 1);        
      }
  
      // This method is executed by another thread
      public void Thread2() {        
          // Note: m_value must be read after m_flag is read
          if (Volatile.Read(ref m_flag) == 1)
          Console.WriteLine(m_value);        
      }    
  }
  </code></pre>
  
  <p>the cpu will wait for the commands before <code>Volatile.Write(ref m_flag, 1);</code> before starting to write to <code>m_flag</code>?</p>
  
  <p>And how is that helps the threads synchronization?</p>