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 ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.