title: Concurrent collection enumerator
body: <p>I'm currently programming my own implementation of priority queue / sorted list and I would like to have it concurrent.
  In order to have it thread safe I'm using <code>lock(someObject)</code> and I would like to verify some behavior of mutexes in C#.</p>
  
  <p>Inner representation of my sorted list is basically linked list with <code>head</code> and slots linked together.
  Something like:</p>
  
  <pre><code>internal class Slot
  {
      internal T Value;
      internal Slot Next;
  
      public Slot(T value, Slot next = null)
      {
          Value = value;
          Next = next;
      }
  }
  </code></pre>
  
  <p>Every time I'm manipulating with <code>head</code> I have to use <code>lock(someObject)</code>because of thread safety.
  In order to implement <code>ICollection</code> interface I have to implement <code>public IEnumerator&lt;T&gt; GetEnumerator()</code>. In this method I have take my <code>head</code> and read from it so I should use mutex.</p>
  
  <pre><code>public IEnumerator&lt;T&gt; GetEnumerator()
  {
      lock (syncLock)
      {
          var curr = head;
          while (curr != null)
          {
              yield return curr.Value;
              curr = curr.Next;
          }
      }
  }
  </code></pre>
  
  <p>My question is: Is <code>syncLock</code> locked for whole time in enumerator (so it will be unlocked after reaching end of the method) or it is automatically unlocked after yielding value?</p>