Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between events and semaphores

I already searched for this subject but couldn't understand it very well. What are the main differences between events and semaphores?

like image 467
pMpC Avatar asked Feb 18 '26 02:02

pMpC


1 Answers

An event generally has only two states, unsignaled or signaled. A semaphore has a count, and is considered unsignaled if the count is zero, and signaled if the count is not zero. In the case of Windows, ReleaseSemaphore() increments a semaphore count, and WaitForSingleObject(...) with a handle of a semaphore will wait (unless the timeout parameter is set to zero) for a non-zero count, then decrement the count before returning.

like image 78
rcgldr Avatar answered Feb 20 '26 18:02

rcgldr