title: Interlocked.Exchange clarification
body: <p>I have a few simple (hopefully) questions that I have been unable to find answers for - </p>
  
  <p>Say I have objects a, b that are accessible to multiple threads.</p>
  
  <pre><code>Interlocked.Exchange(ref a, b)
  </code></pre>
  
  <p>If 'b' is not volatile, will this operation treat it as such? i.e. will it take the latest value of this variable from memory? If so, is that read 'atomic' with the write? I understand that the main purpose of Interlocked.Exchange is that you will get the previous value of 'a' as an atomic operation with the new write. But my main confusion is around what value of 'b' is actually written to 'a'.</p>
  
  <p>My second question is related to a quote in this article:</p>
  
  <p><a href="http://igoro.com/archive/volatile-keyword-in-c-memory-model-explained/" rel="nofollow">http://igoro.com/archive/volatile-keyword-in-c-memory-model-explained/</a></p>
  
  <p>"One interesting point is that all writes in C# are volatile according to the memory model as documented here and here, and are also presumably implemented as such. The ECMA specification of the C# language actually defines a weaker model where writes are not volatile by default."</p>
  
  <p>Is this true? If so, is there a purpose of Interlocked.Exchange if one doesn't care about the previous value of 'a'? (pertaining to my first example). I don't see any other articles or comments on StackOverflow around every write being volatile. I understand, however, that writes are atomic.</p>
  
  <p>Edit: If the answer to my first question is that 'b' is not treated as volatile, and the answer to my second question is that writes are indeed volatile, then a follow up is, when is interlocked.exhange useful if we don't care about the previous value of 'a'?</p>