title: The need for volatile modifier in double checked locking in .NET
body: <p>Multiple texts say that when implementing double-checked locking in .NET the field you are locking on should have volatile modifier applied. But why exactly? Considering the following example:</p>
  
  <pre><code>public sealed class Singleton
  {
     private static volatile Singleton instance;
     private static object syncRoot = new Object();
  
     private Singleton() {}
  
     public static Singleton Instance
     {
        get 
        {
           if (instance == null) 
           {
              lock (syncRoot) 
              {
                 if (instance == null) 
                    instance = new Singleton();
              }
           }
  
           return instance;
        }
     }
  }
  </code></pre>
  
  <p>why doesn't "lock (syncRoot)" accomplish the necessary memory consistency? Isn't it true that after "lock" statement both read and write would be volatile and so the necessary consistency would be accomplished?</p>