ABSTRACT

Counting semaphores are more versatile; they can be used for event notification and interthread synchronization. Mutual exclusion pertains to controlling threads’ access to certain application areas. Counting semaphores can be used for event notification, as in a producer-consumer application. In this application, the consumer attempts to get the counting semaphore before “consuming” a resource; the producer increases the semaphore count whenever it makes something available. The characteristics of each counting semaphore are found in its Control Block. Counting Semaphore Control Blocks can be located anywhere in memory, but it is most common to make the Control Block a global structure by defining it outside the scope of any function. One of the most dangerous pitfalls associated in using semaphores for mutual exclusion is the so-called deadly embrace. The producer creates an event notification by placing an instance in the counting semaphore.