title: Is CAS (compare and swap) thread safe while collection is iterated on?
body: <p>(1) In the below program if Swap and Iterate functions are called on two different threads, would it be safe to swap while collection is iterated on?</p>
  
  <p>(2) Do I really need interlocked exchange as read/write to references are atomic (guaranteed by CLR), suppose Interlocked is required for release semantics for weak memory models? </p>
  
  <pre><code>class someClass
  {
         public void Swap()
         {
             Queue&lt;SomeType&gt; newQueue = new Queue&lt;SomeType&gt;();
             var oldQueue = Interlocked.Exchange(ref queue, newQueue);
             //Perform operation on old queue
         }
  
         public void Iterate()
         {
             foreach(var someTypeObject in queue)
             {
                //Do Something
             }
          }
  
         Queue&lt;SomeType&gt; queue = new Queue&lt;Sometype&gt;();
  }
  </code></pre>