title: How to check the state of a semaphore
body: <p>I want to check the state of a <code>Semaphore</code> to see if it is signalled or not (so if t is signalled, I can release it). How can I do this? </p>
  
  <p><strong>EDIT1:</strong></p>
  
  <p>I have two threads, one would wait on semaphore and the other should release a <code>Semaphore</code>. The problem is that the second thread may call <code>Release()</code> several times when the first thread is not waiting on it. So the second thread should detect that if it calls <code>Release()</code> it generate any error or not (it generate an error if you try to release a semaphore if nobody waiting on it). How can I do this? I know that I can use a flag to do this, but it is ugly. Is there any better way? </p>