0% found this document useful (0 votes)
29 views

Semaphore

Semaphore is an integer variable that allows for synchronization between concurrent processes. It was proposed by Dijkstra in 1965 as a technique for managing concurrent processes using a simple integer value. There are two types of semaphores: binary semaphores, which can have values of only 0 or 1 for mutual exclusion, and counting semaphores, where the value indicates the number of available resources and the value is incremented or decremented as resources are added or removed. Semaphores use two atomic operations - P() and V() - to wait on or signal the semaphore.

Uploaded by

rambabu mahato
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Semaphore

Semaphore is an integer variable that allows for synchronization between concurrent processes. It was proposed by Dijkstra in 1965 as a technique for managing concurrent processes using a simple integer value. There are two types of semaphores: binary semaphores, which can have values of only 0 or 1 for mutual exclusion, and counting semaphores, where the value indicates the number of available resources and the value is incremented or decremented as resources are added or removed. Semaphores use two atomic operations - P() and V() - to wait on or signal the semaphore.

Uploaded by

rambabu mahato
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Semaphore

Semaphore is an integer variable which is used in mutual exclusion manner by


various concurrent cooperative process in order to achieve synchronization.
In 1965, Dijkstra proposed a new and very significant technique for managing
concurrent processes by using the value of a simple integer variable to
synchronize the progress of interacting processes. This integer variable is called
a semaphore.
So it is basically a synchronizing tool and is accessed only through two low
standard atomic operations.
The least value for a Semaphore is zero (0). The Maximum value of a Semaphore
can be anything. The Semaphores usually have two operations. The two
operations have the capability to decide the values of the semaphores.
The two Semaphore Operations are:
1. P(S) , Wait ( ) , Sleep ( ) , Down ( )

Critical Section

2. V(S) , Signal ( ) , Wake up ( ) , Up ( )

Types of Semaphores
There are two types of Semaphores.
1. Binary Semaphore
2. Counting Semaphore
1. Binary Semaphore
 It is a special form of semaphore used for implementing mutual exclusion,
hence it is often called a Mutex Locks.
 A binary semaphore is initialized to 1 and only takes the
values 0 and 1 during the execution of a program.
 In Binary Semaphore, the wait operation works only if the value of
semaphore = 1, and the signal operation succeeds when the semaphore= 0.
 Binary Semaphores are easier to implement than counting semaphores.
 If the Value of Binary Semaphore is 1, then the process has the capability
to enter the critical section area.
 If the value of Binary Semaphore is 0 then the process does not have the
capability to enter the critical section area.

P1

NCS
Entry section
P (S)
{
While (S<= 0); //no operation
S - -;
}

Critical Section

Exit Section
V (S)
{
S++;
}

NCS
2. Counting Semaphore
 Here the semaphore count is used to indicate the number of available
resources.
 If the resources are added then the semaphore count automatically gets
incremented and if the resources are removed, the count is decremented.
Counting Semaphore has no mutual exclusion.

P1

NCS
Entry section
P (S)
{
S value= S value – 1;
If (S value < 0)
{
Put process (PCB) in suspended list Sleep ( );
}
Else
Return;
}

Critical Section

Exit Section
V (S)
{
S value= S value +1;
If (S value < = 0)
{
Select a process from suspended list
&&
wake up ( );
}
}

NCS

You might also like