Reset semaphore

What is the best way to reset a semaphore that has threads waiting on it. Right now all I can think of is just a while loop and freeing up the semaphore until the semaphore is completely eliminated. I'm not sure what is the best.

semaphore.Close();
semaphore = new Semaphore(0,1);

or

while(true)
{
   try
   {
      semaphore.Release();
   }
   catch
   {
      break;
   }
}
semaphore = new Semaphore(0,1);
+3
source share
2 answers

If you want to do this, are you sure you want to start with Semaphore? Perhaps it might be more appropriate ManualResetEvent?

+4
source

, , , . , . , , catch catch (SemaphoreFullException).

, , . - , , WaitOne , , , Release, SemaphoreFullException.

"" - , : . , , , , .,.

+2

Source: https://habr.com/ru/post/1770763/


All Articles