266 EMBEDDED SYSTEMS
To illustrate the idea of a counting semaphore, consider a car park with space for
50 cars. us, the semaphore is initialized to 50, meaning that 50 cars can come into the
car park. e semaphore value is incremented or decremented as cars enter and leave the
parking lot. Every time a car enters the car park, the value of the semaphore is decre-
mented by one. When a car leaves the parking area, the semaphore is incremented by 1.
When, say, the semaphore value is 20, it implies that there is space for 20 more cars.
When the parking lot is full, the semaphore value is 0, and a new car entering it
cannot park inside, as the semaphore value becomes negative.
Similar is the case of an operating system. is can be used in ...