title: C# Memory Barriers
body: <p>I have a question about memory barriers in C#.
  If a write statment is the last statement in a method, for example (the variable v2 is the one of concern):</p>
  
  <pre><code>int _v1 = 0;
  int _v2 = 0
  
  void X()
  {
      _v1 = 2;
      _v2 = 3;
     Thread.MemoryBarrier();
  }
  </code></pre>
  
  <p>Is the memory barrier statment necessary as the _v2 write is the last statement. In other words, does the processor recognize that this is the end of a method and should flush its cache to the memory.</p>
  
  <p>Thanks in advance.</p>