title: reference assignment is atomic so why is Interlocked.Exchange(ref Object, Object) needed?
body: <p>In my multithreaded asmx web service I had a class field _allData of my own type SystemData which consists of few <code>List&lt;T&gt;</code> and <code>Dictionary&lt;T&gt;</code> marked as <code>volatile</code>. The system data (<code>_allData</code>) is refreshed once in a while and I do it by creating another object called <code>newData</code> and fill it's data structures with new data. When it's done I just assign </p>
  
  <pre><code>private static volatile SystemData _allData
  
  public static bool LoadAllSystemData()
  {
      SystemData newData = new SystemData();
      /* fill newData with up-to-date data*/
       ...
      _allData = newData.
  } 
  </code></pre>
  
  <p>This should work since the assignment is atomic and the threads that have the reference to old data keep using it and the rest have the new system data just after assignment. However my collegue said that instead of using <code>volatile</code> keyword and simple assigment I should use <code>InterLocked.Exchange</code> because he said that on some platforms it's not guaranteed that reference assignment is atomic. Moreover: when I declare <code>the _allData</code> field as <code>volatile</code> the </p>
  
  <pre><code>Interlocked.Exchange&lt;SystemData&gt;(ref _allData, newData); 
  </code></pre>
  
  <p>produces warning "a reference to a volatile field will not be treated as volatile" What should I think about this?</p>