- Counting and binary semaphores. The value of a counting semaphore can range over an unrestricted domain.
- The value of a binary semaphore can range only between 0 and 1. On some systems, binary semaphores are known as mutex locks, as they are locks that provide mutual exclusion.
- We can use binary semaphores to deal with the critical-section problem for multiple processes. The processes share a semaphore, mutex, initialized to 1. Each process is organized as shown in Fig. 6.7.
Mutual-exclusion implementation with semaphores.
- Counting semaphores can be used to control access to a given resource consisting of a finite number of instances. The semaphore is initialized to the number of resources available.
- Each process that wishes to use a resource performs a operation on the semaphore (thereby decrementing the ). When a process releases a resource, it performs a operation (incrementing the ).
- When the for the semaphore goes to 0, all resources are being used. After that, processes that wish to use a resource will block until the count becomes greater than 0.