title: How to enforce memory ordering with gcc on x86
body: <p>I want to share a data struct between threads (gcc, Linux, x86).
  Let's say I have the following code in thread A:</p>
  
  <pre><code>shared_struct-&gt;a = 1;
  shared_struct-&gt;b = 1;
  shared_struct-&gt;enable = true;
  </code></pre>
  
  <p>Thread B is a periodic task that checks that struct first for the <code>enable</code> flag.</p>
  
  <p>I think that the compiler can reorder the writes in thread A, so thread B can see inconsistent data. I am familiar with memory barriers on ARM, but <strong>how do I ensure write ordering on x86?</strong> Is there a better way than <code>volatile</code>?</p>
  
  <p>I just want to set a consistent state in the struct, "flush" everything to memory and set an enable flag at the end.</p>