Conditional Variable vs Semaphore

Viewed 103185

When to use a semaphore and when to use a conditional variable?

8 Answers

semaphore need to know the count upfront for initialization. There is no such requirement for condition variables.

The the mutex and conditional variables are inherited from semaphore.

  • For mutex, the semaphore uses two states: 0, 1
  • For condition variables the semaphore uses counter.

They are like syntactic sugar

conditionalVar + mutex == semaphore

Related