title: Shared Resource Lock
body: <p>I'm using C# on .NET 4.5 - Web API Self Host.
  Server-side I've a process that is not thread safe: it can serve one request at a time.
  How can I lock this resource (process) in the controller code, so that clients are served sequentially, waiting for the resource to be freed before using it?
  Something like:</p>
  
  <pre><code>while(true){
      if(!process.isLocked)
          break;
  }
  
  lock(process)
  do(work)
  unlock(process)
  warn(others)
  </code></pre>
  
  <p>Any code snippet or suggestion are appreciated. Thanks in advance.</p>