A semaphore is a mechanism for avoiding race conditions. But what's the significance of the initial value of a semaphore?
Say that a semaphore has an initial value of 5, is it that 5 processes can access some shared resource simultaneously?
My knowledge of semaphores is rusty, but if you create a semaphore with an initial count of 5, it means that 5 threads (not processes) can access the semaphore simultaneously. Have a look at these links for some more details:
Semaphores are a way of coordinating multiple threads of control, not just for mutual exclusion. For example, a classical fixed-size producer-consumer queue may use a semaphore initialized to a non-zero value for producers so that they block when there are too many elements in the buffer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With