AfterAcademy Tech
•
14 Nov 2019

In a system, we have a limited amount of resources that are being shared between various processes. One resource should be used by only one process at a time. This is called process synchronization. So, in an Operating System, we must have synchronization between various processes. This synchronization between processes can be achieved with the help of semaphore. So, in this blog, we will learn about semaphore and we will also look at the types of a semaphore.
Before starting this blog, you should know the concept of Process Synchronization(read the process synchronization blog from here).
A semaphore is a variable that indicates the number of resources that are available in a system at a particular time and this semaphore variable is generally used to achieve the process synchronization. It is generally denoted by "S". You can use any other variable name of your choice.
A semaphore uses two functions i.e. wait() and signal(). Both these functions are used to change the value of the semaphore but the value can be changed by only one process at a particular time and no other process should change the value simultaneously.
The wait() function is used to decrement the value of the semaphore variable "S" by one if the value of the semaphore variable is positive. If the value of the semaphore variable is 0, then no operation will be performed.
wait(S) {
while (S == 0); //there is ";" sign here
S--;
}
The signal() function is used to increment the value of the semaphore variable by one.
signal(S) {
S++;
}
There are two types of semaphores:
This is all about semaphores. Hope you learned something new today.
Do share this blog with your friends to spread the knowledge. Visit our YouTube channel for more content. You can read more blogs from here.
Keep Learning 🙂
Team AfterAcademy!
AfterAcademy Tech
In this blog, we will study various types of relationships in DBMS which help in defining the association between various entities. Also, we will discuss the types of participation constraints which may exist between the relationship and the entity type.

AfterAcademy Tech
In this blog, we will learn about the fragmentation problem that occurs during memory allocation. We will also study the types of fragmentation i.e. internal fragmentation and external fragmentation.

AfterAcademy Tech
In this blog, we will learn about the difference between Mutex and Semaphore in the Operating System. We will first learn about Mutex and Semaphore and after that, we will find the difference between them.

AfterAcademy Tech
In this blog, we will learn how to join two tables in DBMS. We will also learn about the various types of joins, mainly the inner and the outer join.
