title: Will a read-write race condition alter the data read and written simultaneously?
body: <p>For example if I have the following code:  </p>
  
  <pre><code>SomeType obj;  
  
  void GUIThread()  
  {  
      ...  
      while (true)  
          // Read and print the content of obj  
      ...  
  }  
  
  void workerThread()  
  {  
      ...  
      // Do some calculation and write the result into obj  
      ...  
  }  
  </code></pre>
  
  <p>For performance reasons, I can't afford to use mutex or anything alike on <code>obj</code>, and I don't need exact accuracy of what <code>GUIThread</code> prints (<code>obj</code> stores the running computation results of <code>workerThread</code>, which can be considered as a "running total". What <code>GUIThread</code> needs to do  is just to show the approximate progress of the calculation being done in <code>workerThread</code>). What I want to make sure is that the read-write race condition between <code>GUIThread</code> and <code>workerThread</code> doesn't alter the data stored in <code>obj</code>, and won't cause the program to crash. Is that true?  </p>
  
  <p>P.S. <code>SomeType</code> contains built-in integer types and a <code>std::bitset&lt;T&gt;</code>, but only the former will be accessed simultaneously. The <code>bitset</code> remains untouched by <code>GUIThread</code>.  </p>
  
  <p>P.P.S.  Maybe this is a little bit out of the topic...but I think I can store the running results in a cache in <code>workerThread</code>, and only update the actually protected (either by atomicity or mutex locking or whatever) every relatively long time period. To achieve this, I need to make sure that if the following code will work as intended:  </p>
  
  <pre><code>struct SomeOtherType  
  {  
      int a, b, c, d;  // And other primitive types  
  }  
  
  std::atomic&lt;SomeOtherType&gt; data;  // Will this work?  
  </code></pre>
  
  <p>I wonder if this can protect <code>SomeOtherType</code>, and I think it can since there are only primitive types in <code>SomeOtherType</code>.</p>