title: Does std::atomic access serve as a memory barrier?
body: <p>Can the compiler reorder instructions on atomics, or do atomics serve as a memory barrier? 
  Put again, can instructions written after an atomic instruction execute before the atomic instruction?</p>
  
  <p>See the following code. If <code>useMapA = false</code> is moved before <code>mapB</code> is updated and the reading thread begins, we will use an invalid <code>mapB</code>.</p>
  
  <p>Note: the update thread only happens once every 15 minutes, so we have a very well structured flow, and a way to avoid using an expensive lock call!</p>
  
  <pre><code>std::atomic&lt;bool&gt; useMapA;
  std::map&lt;string, string&gt; mapA, mapB;
  
  public void updateMap(map&lt;string, string&gt;* latestMap) {
      if (useMapA) {
          mapB = std::move(*latestMap);
          useMapA = false;
      } else {
          mapA = std::move(*latestMap);
          useMapA = true;
      }
  }
  
  inline map&lt;string, string&gt;&amp; getMap() {
      return useMapA ? mapA : mapB;
  }
  </code></pre>
  
  <p>Edit: I am interested in trading away being 100% thread-safe for speed (time = money). This read function needs to run really fast. You can assume that 15 minutes is long enough to avoid race conditions that would be caused if this time was much shorter.</p>