Semaphore Introduction

Semaphores are assorted data types with 2 areas set of procedures and non-negative integers within a waiting list. It is utilized to explain precarious section drawbacks, and through utilizing 2 processes, it shall be explained. Pause and signal are utilized for the technical organization. It may be a variable utilized to control access to a shared supply by manifold threads and escape critical segment drawbacks in a system like a multitasking process. Semaphores permit a random resource count is known as calculating semaphores.

Levels of the Operation

There are the levels that come with life that may assist with accepting semaphores. The levels are as follows −

  • Running − it circumstances the operation within an implementation.

  • Ready − it states the operation that needs to run.

  • Idle − the operation tracks once no procedures are organizing

  • Blocked − the procedures may not be ready for a splitting operation. It might be stimulated through some peripheral movements

  • Complete − once a procedure implements its ultimate declaration

  • Inactive − The operation is stimulated at some opinion. The early stage of the technique


Semaphore S should be prepared with a price of a non-negative integer that is greater than 0 and with a null set of procedures.



Operations in Semaphore

Here are the 2 atomic operations wait and signal as shown below.

  • Wait − According to the cost of a non-negative integer whether it has a value, reduces its cost, and method p may endure its implementation and whether it is 0, technique p is inserted to set the element, and the state of the operation p becomes clogged. In this circumstance, method p is believed to get clogged on the semaphore.

  • Signal − According to the cost of the set of techniques, whether it is null, increase the price of the integer and whether it is not null, reveal a random set of methods, and replace the position of p to complete.

Semaphores in Terms of Process Synchronization

Semaphores are synchronization machines utilized to organize the events of manifold procedures within a mainframe. These are utilized to implement Mutex, evade race states, and execute synchronization among techniques.

The wait process reduces the charge of the semaphore, and the indication process improves the price of the semaphore. It is utilized to execute serious segments that are areas of the program that should be implemented through solely one operation at the same time. Operations may organize to shared reserves, like shared recollection or Input/ Output tools.

Types of Semaphores

There are some types of semaphores like this −

  • General semaphore − a semaphore whose number of elements may get random non-negative standards of the set of procedures that are known as general semaphores.

  • Binary semaphore − a semaphore whose number element set of procedures gets solely the values zero and one is known as a binary semaphore and known as mutual exclusion mutex.

  • Strong semaphore − the set of procedures ruins unaffected as such as weak semaphores while the non-negative integer is changed through the waiting list. The elimination of uninformed methods within weak semaphores can lead to famishment whereas within this circumstance, it residues free from malnourishment.

    S<-(0, empty)

  • Busy-wait semaphore − it may not get an element non-negative integer and Semaphore S is recognized through a set of actions. This type of semaphore is within a multi-mainframe system whereas the waiting procedure gets its mainframe and is not degenerative central processing time that might be utilized for calculation.

Pros of a Semaphore

  • Because of the busy queue within the semaphore, there is no consumption of procedure period and reserves. This is because the operations are permitted to enter the precarious segment after satiating a convinced disorder.

  • The users permit flexible administration of reserves.

  • They may not permit more than one operation to enter the precarious segment. Mutex is realized and these are enormously well-organized than other systems for synchronization.

  • The users are machine-autonomous as they split within the machine-autonomous program of the microkernel.

Cons of a Semaphore

  • To escape deadlocks, the signal() and wait() processes get to be implemented within the right sequence.

  • Semaphore coding is difficult and probability of not realizing Mutex.

  • There can be a condition of priority overturn while the procedures getting squat priority get contact to the critical segment than the operations getting greater precedence.


The distinct types of semaphores, advantages, and disadvantages of semaphores are demonstrated in this article. The main drawback of the semaphore is that the person needs a busy queue. Whether a procedure is within the current segment, other actions annoying to enter the precarious segment shall be waiting till the current segment is not engaged through any operation. Once any way in a queue then it may incessantly verify for semaphore value and excess central processing sequence.

Updated on: 15-May-2023


Kickstart Your Career

Get certified by completing the course

Get Started