SlideShare a Scribd company logo
3
Most read
7
Most read
8
Most read
Semaphore
Prepared By: Mr. Sangram A. Patil
Assistant Professor PVPIT,Budhgaon
Semaphore
 Provides solution to impose Mutual exclusion among concurrently executing
processes.
 Semaphore consists of an integer variable S
 S is shared by concurrently executing processes
 S protected variable: accessed and modified by two operations wait() and signal().
 Value of S denotes number shared resources
 Wait() is indicated by symbol P
 Signal() is indicated by V
 P and V are called as semaphore primitives
 Each semaphore has a queue associated with it called as semaphore queue.
semaphore
 Each P operation decrements value of count by 1.
 Each V operation increments value of count by 1.
 P and V ensures that only one process enters in its critical section.
 All other processes waiting to enter in their critical section wait in semaphore
queue
 Semaphore ensures that no process go into busy waiting.
 Moving the process to semaphore queue is called as block operation. In which
process changes state from running state to waiting state.
 Removing process from semaphore queue and place into ready queue called as
wakeup operation.
Semaphores
 Types of Semaphores
There are two main types of semaphores i.e. counting semaphores and binary
semaphores
 Counting Semaphores These are integer value semaphores and have an
unrestricted value domain. These semaphores are used to coordinate the resource
access, where the semaphore count is the number of available resources. If the
resources are added, semaphore count automatically incremented and if the
resources are removed, the count is decremented.
Semaphore
 Binary Semaphores The binary semaphores are like counting semaphores but
their value is restricted to 0 and 1. The wait operation only works when the
semaphore is 1 and the signal operation succeeds when semaphore is 0. It is
sometimes easier to implement binary semaphores than counting semaphores.
semaphore
 Semaphore is defined as
typedef struct
{
int count;
struct processqueue queue;
}semaphore;
Counting Semaphore
 Wait is defined as
wait(semaphore S)
{
S.count--;
if(S. count<0)
{
//Perform block operation
and move the process to
semaphore queue
block();
}
}
 signal is defined as
signal(semaphore S)
{
S.count++;
if(S. count<=0)
{
//Perform wakeup operation
and move the process
to ready queue
wakeup();
}
}
semaphore
 Critical section can be accessed by
while(TRUE)
{
wait(S);
//Critical Section
signal(S);
//Remainder section
}
Semaphore
Binary Semaphore
 Wait operation
wait(Semaphore S)
{
if(S.count==1)
{
s.count=0
}
else
{
//block this process and place into
Semphore queue
block();
}
}
 Signal operation
signal(Semaphore S)
{
if(Semaphore queue is empty)
{
s.count=1
}
else
{
//select the process from semaphore
queue and wakeup();
block();
}
}
Binary Semaphore
while(TRUE)
{
wait(S);
//Critical Section
signal(S);
//Remainder Section
}
Semaphore
Disadvantages
 Semaphore with waiting queue may result in situation where two or more
processes waiting indefinitely. These processes are called as deadlocked.
 Priority inversion occurs: Low priority process executes on high priority process.

More Related Content

PPTX
Semophores and it's types
PPTX
File System in Operating System
PPTX
Critical Section in Operating System
PPTX
Directory structure
PPTX
PPTX
Deadlock
PPT
Packages and interfaces
PDF
operating system structure
Semophores and it's types
File System in Operating System
Critical Section in Operating System
Directory structure
Deadlock
Packages and interfaces
operating system structure

What's hot (20)

PPTX
Deadlocks in operating system
PDF
Memory management
PPT
Part 1 - PROCESS CONCEPTS
PPTX
Deadlock- Operating System
PPT
The process states
PPTX
Producer consumer
PDF
Semaphores
PPTX
INTER PROCESS COMMUNICATION (IPC).pptx
PPTX
Cpu scheduling
PPT
process creation OS
PPT
Classical problem of synchronization
PPTX
Dead Lock in operating system
PPT
Applet life cycle
PPTX
process State Models
PPTX
Process management in linux
PDF
Resource management
PPTX
Lecture 14 run time environment
PPTX
Process synchronization
PPT
deadlock avoidance
Deadlocks in operating system
Memory management
Part 1 - PROCESS CONCEPTS
Deadlock- Operating System
The process states
Producer consumer
Semaphores
INTER PROCESS COMMUNICATION (IPC).pptx
Cpu scheduling
process creation OS
Classical problem of synchronization
Dead Lock in operating system
Applet life cycle
process State Models
Process management in linux
Resource management
Lecture 14 run time environment
Process synchronization
deadlock avoidance
Ad

Similar to Semaphore (20)

PPTX
Working of semaphore in operating system level
PPTX
PPT 123456617829291912192891semaphores.pptx
PPT
Mca ii os u-2 process management & communication
PPT
Lecture18-19 (1).ppt
PDF
Os unit 3
PPT
Chapter 6 - Process Synchronization
PDF
Unit2-Part2-MultithreadAlgos.pptx.pdf
PPTX
Semaphores SEMAPHORES Semaphores SEMAPHORES
PPT
CChapter4.pptCChapter4.pptCChapter4.pptCChapter4.pptCChapter4.ppt
PPT
chapter-7-runtime-environments.ppt
PPT
Inter process communication
PDF
Semaphore in Java with Example.pdf
PPTX
JAVA programming language made easy.pptx
PPTX
Semaphore
PPT
OS Process Synchronization, semaphore and Monitors
PPTX
UNIT 2 programming in java_operators.pptx
PPT
Unit 3 principles of programming language
PPTX
Compiler Design_Run time environments.pptx
PPTX
Operating system 24 mutex locks and semaphores
Working of semaphore in operating system level
PPT 123456617829291912192891semaphores.pptx
Mca ii os u-2 process management & communication
Lecture18-19 (1).ppt
Os unit 3
Chapter 6 - Process Synchronization
Unit2-Part2-MultithreadAlgos.pptx.pdf
Semaphores SEMAPHORES Semaphores SEMAPHORES
CChapter4.pptCChapter4.pptCChapter4.pptCChapter4.pptCChapter4.ppt
chapter-7-runtime-environments.ppt
Inter process communication
Semaphore in Java with Example.pdf
JAVA programming language made easy.pptx
Semaphore
OS Process Synchronization, semaphore and Monitors
UNIT 2 programming in java_operators.pptx
Unit 3 principles of programming language
Compiler Design_Run time environments.pptx
Operating system 24 mutex locks and semaphores
Ad

More from sangrampatil81 (20)

PPTX
Memory Management
PPTX
virtual memory
PPTX
IO hardware
PPTX
File system structure
PPTX
File management
PPTX
Disk structure
PPTX
Directory implementation and allocation methods
PPTX
Page replacement algorithms
PPTX
Methods for handling deadlock
PPTX
Monitors
PPTX
Classical problems of process synchronization
PPTX
System programs
PPTX
System programs
PPTX
Services and system calls
PPTX
Operating system structure
PPTX
Operating system deign and implementation
PPTX
Pointer to array and structure
PPTX
Pointer arithmetic in c
PPTX
Pointer in c
PPTX
Structure in c language
Memory Management
virtual memory
IO hardware
File system structure
File management
Disk structure
Directory implementation and allocation methods
Page replacement algorithms
Methods for handling deadlock
Monitors
Classical problems of process synchronization
System programs
System programs
Services and system calls
Operating system structure
Operating system deign and implementation
Pointer to array and structure
Pointer arithmetic in c
Pointer in c
Structure in c language

Recently uploaded (20)

PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Understanding Forklifts - TECH EHS Solution
PPTX
assetexplorer- product-overview - presentation
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Introduction to Artificial Intelligence
PDF
medical staffing services at VALiNTRY
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Reimagine Home Health with the Power of Agentic AI​
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PTS Company Brochure 2025 (1).pdf.......
Understanding Forklifts - TECH EHS Solution
assetexplorer- product-overview - presentation
Wondershare Filmora 15 Crack With Activation Key [2025
Introduction to Artificial Intelligence
medical staffing services at VALiNTRY
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Upgrade and Innovation Strategies for SAP ERP Customers
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms II-SECS-1021-03
Design an Analysis of Algorithms I-SECS-1021-03
history of c programming in notes for students .pptx
Odoo POS Development Services by CandidRoot Solutions
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Semaphore

  • 1. Semaphore Prepared By: Mr. Sangram A. Patil Assistant Professor PVPIT,Budhgaon
  • 2. Semaphore  Provides solution to impose Mutual exclusion among concurrently executing processes.  Semaphore consists of an integer variable S  S is shared by concurrently executing processes  S protected variable: accessed and modified by two operations wait() and signal().  Value of S denotes number shared resources  Wait() is indicated by symbol P  Signal() is indicated by V  P and V are called as semaphore primitives  Each semaphore has a queue associated with it called as semaphore queue.
  • 3. semaphore  Each P operation decrements value of count by 1.  Each V operation increments value of count by 1.  P and V ensures that only one process enters in its critical section.  All other processes waiting to enter in their critical section wait in semaphore queue  Semaphore ensures that no process go into busy waiting.  Moving the process to semaphore queue is called as block operation. In which process changes state from running state to waiting state.  Removing process from semaphore queue and place into ready queue called as wakeup operation.
  • 4. Semaphores  Types of Semaphores There are two main types of semaphores i.e. counting semaphores and binary semaphores  Counting Semaphores These are integer value semaphores and have an unrestricted value domain. These semaphores are used to coordinate the resource access, where the semaphore count is the number of available resources. If the resources are added, semaphore count automatically incremented and if the resources are removed, the count is decremented.
  • 5. Semaphore  Binary Semaphores The binary semaphores are like counting semaphores but their value is restricted to 0 and 1. The wait operation only works when the semaphore is 1 and the signal operation succeeds when semaphore is 0. It is sometimes easier to implement binary semaphores than counting semaphores.
  • 6. semaphore  Semaphore is defined as typedef struct { int count; struct processqueue queue; }semaphore;
  • 7. Counting Semaphore  Wait is defined as wait(semaphore S) { S.count--; if(S. count<0) { //Perform block operation and move the process to semaphore queue block(); } }  signal is defined as signal(semaphore S) { S.count++; if(S. count<=0) { //Perform wakeup operation and move the process to ready queue wakeup(); } }
  • 8. semaphore  Critical section can be accessed by while(TRUE) { wait(S); //Critical Section signal(S); //Remainder section }
  • 10. Binary Semaphore  Wait operation wait(Semaphore S) { if(S.count==1) { s.count=0 } else { //block this process and place into Semphore queue block(); } }  Signal operation signal(Semaphore S) { if(Semaphore queue is empty) { s.count=1 } else { //select the process from semaphore queue and wakeup(); block(); } }
  • 13. Disadvantages  Semaphore with waiting queue may result in situation where two or more processes waiting indefinitely. These processes are called as deadlocked.  Priority inversion occurs: Low priority process executes on high priority process.