5

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?

Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
freenight
  • 1,069
  • 3
  • 13
  • 19

2 Answers2

6

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:

Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
Jason Evans
  • 28,906
  • 14
  • 90
  • 154
3

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
  • 41,404
  • 5
  • 117
  • 189