Semaphores
We have seen mailboxes and message queues as communication objects; when there is no data to exchange, a semaphore may be more appropriate.
A semaphore is a counter that takes positive integer values called units. Threads release units to and wait for units from the semaphore; this can be used for various purposes:
-
to indicate that some event has occurred (this can also be done by a data mailbox or message queue, but if there is no data involved, a semaphore is more efficient).
-
to maintain a free/busy state on some shared resource.
-
as a cheap response object
INtime semaphores, which are very similar to Windows semaphores, offer a number of improvements:
-
priority based queuing (Windows only offers FIFO queuing);
-
multi-unit wait and release (Windows only offers multi-unit release);
-
deterministic waiting times