Semaphores are two-field data types, one of which is a non-negative type of integer S.V and the other is a set of processes in a queue S.L. It is used to address critical section problems by using two atomic operations, wait and signal, to synchronize processes in this.
Semaphores in Operating System PDF
Download Full PDF
In this article, we will look more into the Semaphores in Operating Systems according to the GATE Syllabus for (Computer Science Engineering) CSE. Let us read ahead to find out more about it.
Table of Contents
- What are Semaphores in Operating Systems?
- History of Semaphores in Operating Systems
- Types of Semaphores
- Pros of Semaphores
- Cons of Semaphores
What are Semaphores in Operating Systems?
Semaphores refer to the integer variables that are primarily used to solve the critical section problem via combining two of the atomic procedures, wait and signal, for the process synchronization.
The definitions of signal and wait are given below:
Wait
It decrements the value of its A argument in case it is positive. In case S is zero or negative, then no operation would be performed.
wait(A)
{
while (A<=0);
A–;
}
Signal
This operation increments the actual value of its argument A.
signal(A)
{
A++;
}
History of Semaphores in Operating Systems
When the Dutch computer scientist named Edsger Dijkstra and his team were designing an OS for the Electrologica X8, they devised the semaphore concept. And this technology happened to be known as THE multiprogramming system over time. Dijkstra presented a solution to the problem of squandering wake-up signals, which requires storing all of the wake-up calls. According to Dijkstra, instead of providing the wake-up calls to the customer directly, the producer can store them in a variable. Any of the customers can read it at any time they choose.
Semaphore is a variable that keeps all of the wake-up calls that are sent from the producer to the consumer. In kernel mode, it is a variable on which modify, read, and update occur automatically.
Because race conditions can always occur when multiple processes try accessing the variable at the same time, a semaphore cannot be implemented in user mode. It is always dependent on the operating system for implementation.
Types of Semaphores
Semaphores are of the following types:
Binary Semaphore
Mutex lock is another name for binary Semaphore. It can only have two possible values: 0 and 1, and its value is set to 1 by default. It’s used to implement numerous processes to solve critical section problems. Read more on Binary Semaphore here.
Counting Semaphore
Counting Semaphore’s worth can be found anywhere in the world. It’s used to restrict access to a resource with many copies. Read more on Counting Semaphore here.
Pros of Semaphores
Given below are some of the pros of semaphores:
- Only one process is allowed to enter the critical part because of semaphores. They adhere closely to the mutual exclusion principle. Also, they are far more efficient as compared to the other synchronization methods.
- Since the processor time is not wasted in checking whether a condition is met so as to allow a process to access its critical section, there is ultimately no resource wastage due to busy waiting in the semaphores.
- Semaphores are implemented in the microkernel’s machine-independent code. They are, therefore, machine-independent.
Cons of Semaphores
The following are some of the downsides of semaphores:
- Due to how complex semaphores are, the wait and signal actions must be implemented in the proper order to avoid deadlocks.
- Semaphores are very impractical for their usage at the final scale since they reduce modularity. This mainly occurs because the wait, as well as the signal procedures, bar the system from forming an organised layout.
- Semaphores can cause a priority inversion, with low-priority processes getting access to the important portion first and high-priority processes getting access afterwards.
Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Syllabus, GATE Previous Year Question Paper, and more.
Also Explore,
- Batch Operating System
- Binary Semaphores in Operating System
- Contiguous Memory Allocation in Operating System
- Counting Semaphores in Operating System
- Deadlock Detection and Recovery in Operating System
- Deadlock Prevention in Operating System
- Distributed Operating System
- Dynamic Partitioning in Operating System
- Fixed Partitioning in Operating System
- Functions of Operating System
- Methods for Handling Deadlock in Operating System
- Multiprocessing Operating System
- Multiprogramming Operating System
- Multitasking Operating System
- Network Operating System
- Non-Contiguous Memory Allocation in Operating System
- Operating System Services
- Paging in OS
- Process in Operating System
- Process Scheduler in Operating System
- Process Scheduling in Operating System
- Process State in Operating System
- Real-Time Operating System
- Resource Allocation Graph in Operating System
- Time-Sharing Operating System
- Types of Operating System