title: Is Code with Reference Types thread safe?
body: <p>I would like to know if this code is thread safe? I guess yes because Reference Types are thread safe. But in this case, since it is a generic, we can't be sure right?</p>
  <pre><code> public class LifoMsgQueue&lt;T&gt;
      {
          private class Node&lt;E&gt;
          {
              internal Node&lt;E&gt; next;
              internal E msg;
              internal Node(E msg)
              {
                  this.msg = msg;
              }
          }
          private Node&lt;T&gt; top;
          public void Send(T msg)
          {
              Node&lt;T&gt; node = new Node&lt;T&gt;(msg);
              node.next = top;
              top = node;
          }
          public T Receive()
          {
              SpinWait sw = new SpinWait();
              Node&lt;T&gt; oldTop;
              while ((oldTop = top) == null)
                  sw.SpinOnce();
              top = oldTop.next;
              return oldTop.msg;
          }
      }
  </code></pre>