SlideShare a Scribd company logo
1 of 13
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
}
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
}
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

What's hot

Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaRaghu nath
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)Prakhar Maurya
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's typesNishant Joshi
 
Modern operating system.......
Modern operating system.......Modern operating system.......
Modern operating system.......vignesh0009
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OSvampugani
 
Thread model of java
Thread model of javaThread model of java
Thread model of javamyrajendra
 
Fixed partitioning of memory
Fixed partitioning of memoryFixed partitioning of memory
Fixed partitioning of memoryJohn Scott Giini
 
Linux shell env
Linux shell envLinux shell env
Linux shell envRahul Pola
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-SystemsVenkata Sreeram
 
Signal Handling in Linux
Signal Handling in LinuxSignal Handling in Linux
Signal Handling in LinuxTushar B Kute
 
INTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxINTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxLECO9
 
Linux process management
Linux process managementLinux process management
Linux process managementRaghu nath
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor schedulingShashank Kapoor
 

What's hot (20)

Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
 
System calls
System callsSystem calls
System calls
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Modern operating system.......
Modern operating system.......Modern operating system.......
Modern operating system.......
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Semaphores
SemaphoresSemaphores
Semaphores
 
Storage Management
Storage ManagementStorage Management
Storage Management
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Chapter 8 - Main Memory
Chapter 8 - Main MemoryChapter 8 - Main Memory
Chapter 8 - Main Memory
 
Thread model of java
Thread model of javaThread model of java
Thread model of java
 
Fixed partitioning of memory
Fixed partitioning of memoryFixed partitioning of memory
Fixed partitioning of memory
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Signal Handling in Linux
Signal Handling in LinuxSignal Handling in Linux
Signal Handling in Linux
 
INTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptxINTER PROCESS COMMUNICATION (IPC).pptx
INTER PROCESS COMMUNICATION (IPC).pptx
 
Linux process management
Linux process managementLinux process management
Linux process management
 
Deadlock
DeadlockDeadlock
Deadlock
 
Multi processor scheduling
Multi  processor schedulingMulti  processor scheduling
Multi processor scheduling
 

Similar to Semaphore

Mca ii os u-2 process management & communication
Mca  ii  os u-2 process management & communicationMca  ii  os u-2 process management & communication
Mca ii os u-2 process management & communicationRai University
 
Lecture18-19 (1).ppt
Lecture18-19 (1).pptLecture18-19 (1).ppt
Lecture18-19 (1).pptssuserf67e3a
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
Unit2-Part2-MultithreadAlgos.pptx.pdf
Unit2-Part2-MultithreadAlgos.pptx.pdfUnit2-Part2-MultithreadAlgos.pptx.pdf
Unit2-Part2-MultithreadAlgos.pptx.pdfVinayak247538
 
chapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptchapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptssuser0db64b
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationGift Kaliza
 
Semaphore in Java with Example.pdf
Semaphore in Java with Example.pdfSemaphore in Java with Example.pdf
Semaphore in Java with Example.pdfSudhanshiBakre1
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitorssgpraju
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Operating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresOperating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresVaibhav Khanna
 
Describe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfDescribe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfhadpadrrajeshh
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.pptjayverma27
 
Lecture_6_Process.ppt
Lecture_6_Process.pptLecture_6_Process.ppt
Lecture_6_Process.pptwafawafa52
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Cysinfo Cyber Security Community
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)jeffz
 

Similar to Semaphore (20)

Mca ii os u-2 process management & communication
Mca  ii  os u-2 process management & communicationMca  ii  os u-2 process management & communication
Mca ii os u-2 process management & communication
 
Lecture18-19 (1).ppt
Lecture18-19 (1).pptLecture18-19 (1).ppt
Lecture18-19 (1).ppt
 
Os unit 3
Os unit 3Os unit 3
Os unit 3
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Unit2-Part2-MultithreadAlgos.pptx.pdf
Unit2-Part2-MultithreadAlgos.pptx.pdfUnit2-Part2-MultithreadAlgos.pptx.pdf
Unit2-Part2-MultithreadAlgos.pptx.pdf
 
chapter-7-runtime-environments.ppt
chapter-7-runtime-environments.pptchapter-7-runtime-environments.ppt
chapter-7-runtime-environments.ppt
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Semaphore in Java with Example.pdf
Semaphore in Java with Example.pdfSemaphore in Java with Example.pdf
Semaphore in Java with Example.pdf
 
Os3
Os3Os3
Os3
 
Semaphore
SemaphoreSemaphore
Semaphore
 
OS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and MonitorsOS Process Synchronization, semaphore and Monitors
OS Process Synchronization, semaphore and Monitors
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Operating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphoresOperating system 24 mutex locks and semaphores
Operating system 24 mutex locks and semaphores
 
Describe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdfDescribe the difference between a monitor and a semaphoreSolutio.pdf
Describe the difference between a monitor and a semaphoreSolutio.pdf
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
23 concurrency-examples
23 concurrency-examples23 concurrency-examples
23 concurrency-examples
 
19
1919
19
 
Lecture_6_Process.ppt
Lecture_6_Process.pptLecture_6_Process.ppt
Lecture_6_Process.ppt
 
Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1Advanced malwareanalysis training session2 botnet analysis part1
Advanced malwareanalysis training session2 botnet analysis part1
 
The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)The Evolution of Async-Programming (SD 2.0, JavaScript)
The Evolution of Async-Programming (SD 2.0, JavaScript)
 

More from sangrampatil81

Directory implementation and allocation methods
Directory implementation and allocation methodsDirectory implementation and allocation methods
Directory implementation and allocation methodssangrampatil81
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithmssangrampatil81
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlocksangrampatil81
 
Classical problems of process synchronization
Classical problems of process synchronizationClassical problems of process synchronization
Classical problems of process synchronizationsangrampatil81
 
Services and system calls
Services and system callsServices and system calls
Services and system callssangrampatil81
 
Operating system structure
Operating system structureOperating system structure
Operating system structuresangrampatil81
 
Operating system deign and implementation
Operating system deign and implementationOperating system deign and implementation
Operating system deign and implementationsangrampatil81
 
Pointer to array and structure
Pointer to array and structurePointer to array and structure
Pointer to array and structuresangrampatil81
 
Pointer arithmetic in c
Pointer arithmetic in c Pointer arithmetic in c
Pointer arithmetic in c sangrampatil81
 

More from sangrampatil81 (20)

Deadlock
DeadlockDeadlock
Deadlock
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
IO hardware
IO hardwareIO hardware
IO hardware
 
File system structure
File system structureFile system structure
File system structure
 
File management
File managementFile management
File management
 
Disk structure
Disk structureDisk structure
Disk structure
 
Directory structure
Directory structureDirectory structure
Directory structure
 
Directory implementation and allocation methods
Directory implementation and allocation methodsDirectory implementation and allocation methods
Directory implementation and allocation methods
 
Page replacement algorithms
Page replacement algorithmsPage replacement algorithms
Page replacement algorithms
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
Monitors
MonitorsMonitors
Monitors
 
Classical problems of process synchronization
Classical problems of process synchronizationClassical problems of process synchronization
Classical problems of process synchronization
 
System programs
System programsSystem programs
System programs
 
System programs
System programsSystem programs
System programs
 
Services and system calls
Services and system callsServices and system calls
Services and system calls
 
Operating system structure
Operating system structureOperating system structure
Operating system structure
 
Operating system deign and implementation
Operating system deign and implementationOperating system deign and implementation
Operating system deign and implementation
 
Pointer to array and structure
Pointer to array and structurePointer to array and structure
Pointer to array and structure
 
Pointer arithmetic in c
Pointer arithmetic in c Pointer arithmetic in c
Pointer arithmetic in c
 

Recently uploaded

MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 

Recently uploaded (20)

MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 

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 }
  • 9.
  • 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(); } }
  • 12.
  • 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.