title: c++11 how to insert simple memory barrier?
body: <p>I want to insert simple memory barrier, i.e. analog of C# <code>Thread.MemoryBarrier();</code>.
  How can I do this on <em>C++</em>? :</p>
  
  <p>This is my code to modify:</p>
  
  <pre><code>volatile uint32_t curWriteNum;
  
  void ObtainAndCommit(T* val) {
      memcpy(&amp;storage[curWriteNum &amp; MASK], val, sizeof(T));
       // Ensure storage is written before mask is incremented
       // insert memory barrier
       ++curWriteNum;
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>When I posted this question I just wanted to know how to insert memory barrier. But it seems now we discussing how to make my program valid so I adding link to full listing of the class <a href="https://codereview.stackexchange.com/questions/38815/one-reader-one-writer-no-memory-allocation-lock-free-ring-buffer">one reader / one writer no-memory-allocation lock-free ring-buffer</a>.</p>