title: How to guarantee that load completes before store occurs?
body: <p>In the following code, how could one ensure that ptr not incremented until after *ptr has been loaded/assigned/"extracted"?</p>
  
  <pre><code>extern int arr[some_constexpr]; // assume pre-populated
  extern int* ptr; // assume points to non-atomic arr
  int a = *ptr;
  // want "memory barrier/fence" here
  ++ptr;
  </code></pre>
  
  <p>Would an atomic pointer ensure the correct ordering/sequencing?</p>
  
  <pre><code>#include &lt;atomic&gt;
  
  extern int arr[some_constexpr];
  extern std::atomic&lt;int*&gt; ptr;
  int a = *(ptr.load());
  // implicit "memory barrier" achieved here by use of atomics?
  ptr.store(ptr + 1);
  </code></pre>
  
  <p>This relates to a lock-free queue shared between two threads.  I want to ensure that the data associated with the pointer is not lost/corrupted before updating the pointer.</p>