title: Mutual exclusion: is this safe?
body: <p>Is this pattern for mutual exclusion as safe as I think it is? If so, what do you call it?</p>
  
  <pre><code>lock (_lock) {
      if (_flag) return;
      else _flag = true;
  }
  try {
      //critical code...
  }
  finally {
      _flag = false;
  }
  </code></pre>
  
  <p>I want to ensure the critical section, but without the other threads piling up waiting to acquire the lock. Obviously I make sure the flag is set nowhere else. Is there a better way?</p>