title: C++ : std::atomic<bool> and volatile bool
body: <p>I'm just reading the C++ concurrency in action book by Anthony Williams.
  There is this classic example with two threads, one produce data, the other one consumes the data and A.W. wrote that code pretty clear :</p>
  
  <pre><code>std::vector&lt;int&gt; data;
  std::atomic&lt;bool&gt; data_ready(false);
  
  void reader_thread()
  {
      while(!data_ready.load())
      {
          std::this_thread::sleep(std::milliseconds(1));
      }
      std::cout &lt;&lt; "The answer=" &lt;&lt; data[0] &lt;&lt; "\n";
  }
  
  void writer_thread()
  {
      data.push_back(42);
      data_ready = true;
  }
  </code></pre>
  
  <p>And I really don't understand why this code differs from one where I'd use a classic volatile bool instead of the atomic one.
  If someone could open my mind on the subject, I'd be grateful.
  Thanks.</p>