title: Is there any reason to prefer Interlocked over volatile for an Immutable Collection where updates do not depend on previous values?
body: <p>I noticed that in questions discussing immutable collections (e.g. <a href="https://stackoverflow.com/questions/16520816/what-is-the-preferred-method-of-updating-a-reference-to-an-immutable-object">What is the preferred method of updating a reference to an immutable object?</a>)
  it was advised to use <code>Interlocked</code> (or better <code>ImmutableInterlocked</code>). The reason for this seems to be for CAS, since in most cases an immutable collection is updated based off of its previous value. However, suppose I have some class wrapping an immutable collection which I expect to be accessed concurrently and where new values do not depend on old values, would using <code>Interlocked</code> still be preferred? In other words, is there any reason for me to prefer this:</p>
  <pre class="lang-cs prettyprint-override"><code>public class Data {
     private ImmutableList&lt;string&gt; values;
  
     public ImmutableList&lt;string&gt; Read() {
         return Interlocked.CompareExchange(ref values, null, null);
     }
  
     public void Write(IEnumerable&lt;string&gt; update) {
        //some arbitrary transformation that doesn't use values at all
        var newValues = update.Select(x =&gt; x + &quot;-update&quot;).ToImmutableList(); 
  
        Interlocked.Exchange(ref values, newValues);
     }
  }
  </code></pre>
  <p>over this:</p>
  <pre class="lang-cs prettyprint-override"><code>public class Data {
     private volatile ImmutableList&lt;string&gt; values;
  
     public ImmutableList&lt;string&gt; Read() {
         return values;
     }
  
     public void Write(IEnumerable&lt;string&gt; update) {
        //some arbitrary transformation that doesn't use values at all
        var newValues = update.Select(x =&gt; x + &quot;-update&quot;).ToImmutableList();
  
        values = newValues;
     }
  
  }
  </code></pre>