title: Can atomic_thread_fence(acquire) prevent previous loads being reordered after itself?
body: <p>I understand <code>atomic_thread_fence</code> in C++ is quite different with atomic store/loads, and it is not a good practice to understand them by trying to interpret them into CPU(maybe x86)'s mfence/lfence/sfence.</p>
  <p>If I use <code>c.load(memory_order_acquire)</code>, no stores/loads after <code>c.load</code> can be reordered before <code>c.load</code>. However, I think there are no restriction to stores/loads before <code>c.load</code>. I mean some stores/loads before <code>c.load</code> can be reordered after it theoretically.</p>
  <p>However when it comes to <code>atomic_thread_fence(memory_order_acquire)</code>, it involves 3 kinds of objects: the fence, store/loads before this fence and store/loads after this fence.</p>
  <p>I think the fence will certainly prevent store/loads after this fence being reordered before itself, just like atomic store/load. But will it prevent store/loads before this fence being reordered after itself?</p>
  <p>I think the answer is yes with the following searching:</p>
  <ol>
  <li><p>In <a href="https://preshing.com/20130922/acquire-and-release-fences/" rel="nofollow noreferrer">preshing's article</a></p>
  <blockquote>
  <p>An acquire fence prevents the memory reordering of any read which precedes it in program order with any read or write which follows it in program order.</p>
  </blockquote>
  <p>So he does not specify a direction.</p>
  </li>
  <li><p>In <a href="http://www.modernescpp.com/index.php/acquire-release-fences" rel="nofollow noreferrer">modernescpp</a></p>
  <blockquote>
  <p>there is an additional guarantee with the acquire memory barrier. No read operation can be moved after the acquire memory barrier.</p>
  </blockquote>
  <p>So I think he say yes directly?</p>
  </li>
  </ol>
  <p>However, I find no &quot;official&quot; answer in <a href="https://en.cppreference.com/w/cpp/atomic/atomic_thread_fence" rel="nofollow noreferrer">cppreference</a>, it only specifies how fences and atomics interact with each other in different threads.</p>
  <p>but I am not sure, so I have this question.</p>