title: Is yield return reentrant?
body: <p>Can a static function in a static class which uses <code>yield return</code> to return an IEnumerable safely be called from multiple threads?</p>
  
  <pre><code>public static IEnumerable&lt;FooClass&gt; FooClassObjects()
  {
      foreach (FooClassWrapper obj in listOfFooClassWrappers)
      {
          yield return obj.fooClassInst;
      }
  }
  </code></pre>
  
  <p>Will each thread that calls this always receive a reference to each object in the collection? In my situation <code>listOfFooClassWrappers</code> is written to once at the beginning of the program, so I don't need to worry about it changing during a call to this function. I wrote a simple program to test this, and I didn't see any indication of problems, but threading issues can be difficult to suss out and it's possible that the issue simply didn't show up during the runs that I did.</p>
  
  <p>EDIT: <a href="https://stackoverflow.com/questions/1379266/is-yield-return-in-c-sharp-thread-safe">Is yield return in C# thread-safe?</a> is similar but addresses the situation where the collection is modified while being iterated over. My concern has more to do with multiple threads each getting only part of the collection due to a hidden shared iterator given that the class and method are both static.</p>