title: Can another thread see partially created collection when using collection initializer?
body: <p>Imagine this C# code in some method:</p>
  
  <pre><code>SomeClass.SomeGlobalStaticDictionary = new Dictionary&lt;int, string&gt;()
  {
      {0, "value"},
  };
  </code></pre>
  
  <p>Let's say no one is using any explicit memory barriers or locking to access the dictionary. </p>
  
  <p>If no optimization takes place, then the global dictionary should be either null (initial value) or a properly constructed dictionary with one entry.</p>
  
  <p>The question is: Can the effect of the Add call and assigning to SomeGlobalStaticDictionary be reordered such that some other thread would see an empty non-null SomeGlobalStaticDictionary (or any other invalid partially constructed dictionary?)</p>
  
  <p>Does the answer change if SomeGlobalStaticDictionary is volatile?</p>
  
  <p>After reading <a href="http://msdn.microsoft.com/en-us/magazine/jj863136.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/jj863136.aspx</a> (and also its second part) I learned that in theory just because one variable is assigned in source code  other threads might see it differently due to many reasons. I looked at the IL code but the question is whether the JIT compiler and/or CPU are allowed to not "flush" the effect of the Add call to other threads before the assignment of the SomGlobalStaticDictionary.</p>