views:

236

answers:

2

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?

+2  A: 

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.

Barry Kelly
+2  A: 

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:

Jason Evans
thanks for the link
freenight
+1 - Great links
Matthew Murdoch