title: How to create a FIFO/strong semaphore
body: <p>I need to code my own FIFO/strong semaphore in C#, using a semaphore class of my own as a base. I found <a href="https://code.google.com/p/seacowdb/source/browse/trunk/DLRDB.Core/ConcurrencyUtils/FIFOSemaphore.cs?r=29" rel="noreferrer">this example</a>, but it's not quite right since I'm not supposed to be using Monitor.Enter/Exit yet.</p>
  
  <p>These are the methods for my regular semaphore, and I was wondering if there was a simple way to adapt it to be FIFO.</p>
  
  <pre><code>public virtual void Acquire()
  {
  
      lock (this)
      {
  
          while (uintTokens == 0)
          {
  
              Monitor.Wait(this);
  
          }
  
          uintTokens--;
  
      }
  
  }
  
  public virtual void Release(uint tokens = 1)
  {
  
      lock (this)
      {
  
          uintTokens += tokens;
          Monitor.PulseAll(this);
  
      }
  
  }
  </code></pre>