Semaphores
Semaphores are a generalization of mutexes. Maybe it’s better to state the opposite: Mutexes are a special case of the semaphore primitive invented by the Dutch computer scientist Dijkstra. The name semaphore was inspired by synchronization mechanisms used in railways; they are the equivalent to roadside traffic lights.
Before getting into details about the Semaphore class and its properties, let’s take a look at a railway semaphore. Figure 29.23 shows states a semaphore can be in, which are used to communicate actions to train drivers. I’m not an expert in railway design, but the basic idea is simple. One sign indicates the train has to stop, and another indicates it’s safe to pass. An intermediate state sometimes exists, too, indicating ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access