Semaphore is simply a variable that is non-negative and shared between threads. A semaphore is a signalling mechanism, and a thread that is waiting on a semaphore can be signalled by another thread. It uses two atomic operations, 1) Wait, and 2) Signal for the process synchronization.
A
semaphore either allows or disallows access to the resource, which depends on
how it is set up.
Here, are characteristic of a
semaphore:
- It is a mechanism that can be used to provide
synchronization of tasks.
- It is a low-level synchronization mechanism.
- Semaphore will always hold a non-negative
integer value.
- Semaphore can be implemented using test
operations and interrupts, which should be executed using file
descriptors.
Types of Semaphores
The two common kinds of semaphores are
- Counting semaphores
- Binary semaphores.