title: should I insert MemoryBarrier?
body: <p>I have such code:</p>
  
  <pre><code>.....
  private volatile bool _connSharedDisposed;
  ......
  
      // Thread 1
      while (!_connSharedDisposed)
      {
          Thread.Sleep(1);
      }
      CGate.Close();
  
      ......
      // Thread 2
      _connShared.Close();
      _listenerFutInfo.Close();
      _listenerFutInfo.Dispose();
      _listenerFutCommon.Close();
      _listenerFutCommon.Dispose();
      _connShared.Dispose();
      // insert Thread.MemoryBarrier here?
      _connSharedDisposed = true;
  </code></pre>
  
  <p>I'm afraid that <code>_connSharedDisposed = true</code> might be rearranged and receive <code>true</code> before calling <code>_connShared.Dispose()</code>. Is it possible? If my code doesn't work how to fix it? I guess I probably should insert MemoryBarrier to block "rearrange"</p>
  
  <p>Also probably I should use <code>AutoResetEvent</code> instead of <code>bool volatile</code> variable...</p>