title: What is the use case for the atomic exchange (read-write) operation?
body: <p>C++0x specifies the <code>std::atomic</code> template for thread safe atomic access to variables. This template has, among others, a member function <a href="http://www.stdthread.co.uk/doc/headers/atomic/atomic/exchange.html" rel="noreferrer">std::atomic::exchange</a> that <em>atomically stores a new value in "this" and retrieves the existing value of "this".</em></p>
  
  <p>Win32 has a similar function: <a href="http://msdn.microsoft.com/en-us/library/ms683590%28v=vs.85%29.aspx" rel="noreferrer"><code>InterlockedExchange</code></a></p>
  
  <p>Now, what these operations do is simple: atomic read-modify.</p>
  
  <p>What I do not understand is what the <em>point</em> of this operation is. The value read that is returned is "meaningless", because once I can inspect the return value, another thread may already have overwritten it.</p>
  
  <p>So what's the use case for this? <em>What can the information of which value was there just before I wrote my new value into the variable tell me?</em></p>
  
  <p>Note: The <code>compare_exchange</code> / <code>InterlockedCompareExchange</code> semantics do make sense to me, but not the simple exchange semantics.</p>