title: Is it possible to atomically load and store on X86 processors?
body: <p>Can this be done atomically?</p>
  
  <pre><code>void load_and_store(int* dst, int* src) {
    int data = *src;
    *dst = data;
  }
  </code></pre>
  
  <p>If atomic store has to be done with <code>XCHG [addr], EAX</code>, I would have to load the data into <code>EAX</code> first. Then load and store are not atomic.</p>
  
  <p>gcc atomic extension has <code>void __atomic_store (type *ptr, type *val, int memmodel)</code> which looks like being able to do both load and store atomically.</p>