The Linux kernel does provide a semaphore object, along with the usual operations you can perform on a (binary) semaphore:
- A semaphore lock acquire via the down[_interruptible]() (and variations) APIs
- A semaphore unlock via the up() API.
In general, the semaphore is an older implementation, so it's advised that you use the mutex lock in place of it.
An FAQ worth looking at, though, is this: what is the difference between a mutex and a semaphore? They appear to be conceptually similar, but are actually quite different:
- A semaphore is a more generalized form of a mutex; a mutex lock can be acquired (and subsequently released or unlocked) exactly once, while a semaphore can be acquired (and subsequently released) multiple times.
- A mutex is used to protect a critical section from simultaneous access, while a semaphore should be used as a mechanism to signal another waiting task that a certain milestone has been...