Semaphores

A Semaphore $S$ is an integer variable which is accessed through atomic operations.

This approach provides the two operations $wait$ and $signal$.

Two main types of Semaphore:

An implementation must guarantee that no two processes can $wait$ and $signal$ a Semaphore at the same time. The implementation them becomes solving the CS problem. The naive solution leads to busy waiting within the CS, which is not a good solution.

An implementation with no busy waiting might use queues for each Semaphore. Each entry to the queues contains a value for the Semaphore, and a pointer to the next record in the list. This requires a further two operations to be used inside $wait$ and $signal$: