title: Hidden function of finally block?
body: <p>I was reading the <a href="https://referencesource.microsoft.com/#mscorlib/system/Collections/Concurrent/ConcurrentQueue.cs,7e64043e41ae088a" rel="nofollow noreferrer">source codes for <code>ConcurrentQueue</code></a> when I saw this (line 790-811):</p>
  
  <pre><code>//We need do Interlocked.Increment and value/state update in a finally block to ensure that they run
  //without interuption. This is to prevent anything from happening between them, and another dequeue
  //thread maybe spinning forever to wait for m_state[] to be true;
  try
  { }
  finally
  {
      newhigh = Interlocked.Increment(ref m_high);
      if (newhigh &lt;= SEGMENT_SIZE - 1)
      {
          m_array[newhigh] = value;
          m_state[newhigh].m_value = true;
      }
  
      //if this thread takes up the last slot in the segment, then this thread is responsible
      //to grow a new segment. Calling Grow must be in the finally block too for reliability reason:
      //if thread abort during Grow, other threads will be left busy spinning forever.
      if (newhigh == SEGMENT_SIZE - 1)
      {
          Grow();
      }
  }
  </code></pre>
  
  <p>After reading that comment, I still have no idea what it means. What magic does <code>finally</code> block has that the official API would wrap a block of codes into a <code>finally</code> block which has an empty <code>try</code> block? Is there a simple example that would explain this special function of <code>finally</code> block?</p>