title: Which std::sync::atomic::Ordering to use?
body: <p>All the methods of <a href="http://doc.rust-lang.org/std/sync/atomic/struct.AtomicBool.html"><code>std::sync::atomic::AtomicBool</code></a> take a memory ordering (Relaxed, Release, Acquire, AcqRel, and SeqCst), which I have not used before. Under what circumstances should these values be used? The documentation uses confusing “load” and “store” terms which I don’t really understand. For example:</p>
  
  <p>A producer thread mutates some state held by a <a href="http://doc.rust-lang.org/std/sync/struct.Mutex.html"><code>Mutex</code></a>, then calls <a href="http://doc.rust-lang.org/std/sync/atomic/struct.AtomicBool.html"><code>AtomicBool</code></a>::<code>compare_and_swap(false, true, ordering)</code> (to coalesce invalidations), and if it swapped, posts an “invalidate” message to a concurrent queue (e.g. <a href="http://doc.rust-lang.org/std/sync/mpsc/index.html"><code>mpsc</code></a> or a winapi <code>PostMessage</code>). A consumer thread resets the <code>AtomicBool</code>, reads from the queue, and reads the state held by the Mutex. Can the producer use Relaxed ordering because it is preceded by a mutex, or must it use Release? Can the consumer use <code>store(false, Relaxed)</code>, or must it use <code>compare_and_swap(true, false, Acquire)</code> to receive the changes from the mutex?</p>
  
  <p>What if the producer and consumer share a <a href="http://doc.rust-lang.org/std/cell/struct.RefCell.html"><code>RefCell</code></a> instead of a <code>Mutex</code>?</p>