Threads exchange a non-negative variable called semaphore. A semaphore is a signalling mechanism, and another thread can signal a thread that is waiting for a semaphore. For process synchronisation, it employs two atomic operations: 1) wait and 2) signal.
Depending on that it is set up, a semaphore either enables or prevents access to a resource.
Semaphores are integer variables that are using to solve the critical section problem by combining two atomic procedures for process synchronisation: wait and signal.
Advantages of Semaphore
The following are some of the benefits of semaphores:
- Only one process is allow to enter the critical part thanks to semaphores. They closely adhere to the mutual exclusion principle and are far more efficient than other synchronisation methods.
- Because processor time is not wasted unnecessarily checking if a condition is met to allow a process to access the vital region, there is no resource waste due to busy waiting in semaphores.
- Semaphores are implement in the microkernel’s machine-independent code. As a result, they are machine-agnostic.
Disadvantages
The following are some of the drawbacks of semaphores:
- Due to the complexity of semaphores, the wait and signal actions may performing in the correct order to avoid deadlocks.
- Semaphores are impractical for usage at the final scale because they reduce modularity. This occurs because the wait and signal procedures hinder the system from forming a structured layout.
- Semaphores may cause a priority inversion, allowing low-priority processes to access the critical portion first and high-priority processes to access the vital section later.
Interested in learning about similar topics? Here are a few hand-picked blogs for you!
- What is API?
- Phenomena of cloud computing?
- What is sorting algorithm?
- Phenomenal of DNS?
- What is machine learning?