title: Is there a general way to convert a critical section to one or more semaphores?
body: <p>Is there a general way to convert a critical section to one or more semaphores?  That is, is there some sort of straightforward transformation of the code that can be done to convert them?</p>
  
  <p>For example, if I have two threads doing protected and unprotected work like below.  Can I convert them to Semaphores that can be signaled, cleared and waited on?</p>
  
  <pre><code>void AThread()
  {
    lock (this)
    {
      Do Protected Work
    }
  
    Do Unprotected work.
  }
  </code></pre>
  
  <p>The question came to me after thinking about C#'s lock() statement and if I could implement equivalent functionality with an EventWaitHandle instead.</p>