title: C++ std::atomic vs. Boost atomic
body: <p>In my application, I have an int and a bool variable, which are accessed (multiple write/read) by multiple threads. Currently, I am using two mutexes, one for int and one for bool to protect those variables.</p>
  
  <p>I heard about using atomic variables and operators to write lock-free multi-thread program. My questions are</p>
  
  <ol>
  <li>What's the definition of atomic variables and operators?</li>
  <li>What's the main difference between <strong>std::atomic</strong> and
  <strong>boost/atomic.hpp</strong>? Which one is more standard or popular?</li>
  <li>Are these libraries platform-dependent? I am using gnu gcc 4.6 on
  Linux at the moment, but ideally it shall be cross-platform. I heard that the definition of "atomic" actually depends on the hardware as well. Can anyone explain that as well?</li>
  <li>What's the best way to share a bool variable among multiple threads? I would prefer not to use the "<strong>volatile</strong>" keyword.</li>
  </ol>
  
  <p>Are these code thread-safe?</p>
  
  <pre><code>double double_m; // double_m is only accessed by current thread.
  std::atomic&lt;bool&gt; atomic_bool_x;
  atomic_bool_x = true &amp;&amp; (double_m &gt; 12.5);
  
  int int_n; // int_n is only accessed by current thread.
  std::atomic&lt;int&gt; atomic_int_x;
  std::atomic&lt;int&gt; atomic_int_y;
  atomic_int_y = atomic_int_x * int_n;
  </code></pre>