Indeed, Dijkstra and colleagues invented the semaphore as a single primitive for all things related to synchronization; as you will see, one can use semaphores as both locks and condition variables.
Definition
A semaphore is an object with an integer value that we can manipulate with two routines; in the POSIX standard, these routines are sem_wait() P and sem_post() V.
Implementation
Re-think the P implementation. If the critical section is large, we could spend a great deal of time spinning.
Binary Semaphores (Locks)
@todo
reference
- cse170 semaphores and cv
- 信号量与mutex区别
- Goodbyes semaphores
- How are mutexes and semaphores different with respect to their implementation in a Linux kernel? PS - Ealrier mutex was implemented using binary semaphore but that is changed now. Please see below for more reference.