SlideShare a Scribd company logo
Operating System
Concepts
Instructor Name: Muhammad Asif
1
Quick Recap of Previous Lecture
• Software solution to the Critical Section Problem
• Semaphore
• Wait ( )
• Signal ( )
• Types of Semaphore
• Counting semaphore
• Binary semaphore
• Advantages of semaphore
2
Today’s Outlines
• Process Synchronization
• Synchronization Hardware
• Mutex Lock
• Classical Problems of Synchronization
• Bounded Buffer (Producer-Consumer) Problem
• Producer & Consumer Operation
• Solve with help of Semaphore
3
Process Synchronization
• Process Synchronization is a way to coordinate processes that
use shared data.
• It occurs in an operating system among cooperating
processes. While executing many concurrent processes,
• Process synchronization helps to maintain shared data
consistency and cooperating process execution.
• Real World Example:
• An example of synchronize is when army bands coordinate
their musical instruments.
• An example of synchronize is when you and a friend both set
your watch to 12:15.
4
Synchronization Hardware
• Many systems provide hardware support for critical section
Problem.
• The critical section problem could be solved easily in a single-
processor environment:
• if we could disallow interrupts to occur while a shared variable or
resource is being modified.
• In this manner, we could be sure that the current sequence of
instructions would be allowed to execute in order without pre-
emption.
• Unfortunately, this solution is not feasible in a multiprocessor
environment.
• Disabling interrupt on a multiprocessor environment can be
time consuming as the message is passed to all the processors.
• This message transmission lag, delays entry of threads into
critical section and the system efficiency decreases.
5
Mutex Lock
• As the synchronization hardware solution is not easy to
implement for everyone, a strict software approach called
Mutex Locks was introduced.
• In this approach, in the entry section of code:
• A LOCK is acquired over the critical resources modified and used
inside critical section, and in the exit section that LOCK is
released.
• As the resource is locked while a process executes its critical
section hence no other process can access it.
6
Classical Problems of Synchronization
• We will discuss the following three problems:
• Bounded Buffer (Producer-Consumer) Problem
• Dining Philosophers Problem
• The Readers Writers Problem
• Bounded Buffer Problem (Producer-Consumer Problem)
• Which is also called producer consumer problem, is one of
the classic problems of synchronization.
• Problem Statement:
• There is a buffer of n slots and each slot is capable of storing
one unit of data.
• There are two processes running,
namely, producer and consumer, which are operating on the
buffer. 7
Producer & Consumer Problem
8
• Producer & Consumer Problem:
• A producer tries to insert data into an empty slot of the buffer.
• A consumer tries to remove data from a filled slot in the buffer.
• As you might have guessed by now, those two processes won’t
produce the expected output if they are being executed
concurrently.
• There needs to be a way to make the producer and consumer
work in an independent manner.
Producer & Consumer Problem
9
• Solution:
• One solution of this problem is to use semaphores.
• The semaphores which will be used here are:
• S, a binary semaphore which is used to acquire and release
the lock.
• empty, a counting semaphore whose initial value is the
number of slots in the buffer, since, initially all slots are empty.
• full, a counting semaphore whose initial value is 0.
• At any instant, the current value of empty represents the
number of empty slots in the buffer and full represents the
number of occupied slots in the buffer.
Producer & Consumer Problem
10
Semaphore:
S = 1
Semaphore:
Empty = n
Semaphore:
Full = 0
Producer & Consumer Problem
11
• Solution Producer:
• The pseudo-code of the producer function looks like this:
Producer & Consumer Problem
12
• Solution for Producer:
• we can see that a producer first waits until there is at least one
empty slot.
• Then it decrements the empty semaphore because, there will
now be one less empty slot, since the producer is going to
insert data in one of those slots.
• Then, it acquires lock on the buffer, so that the consumer
cannot access the buffer until producer completes its operation.
• After performing the insert operation, the lock is released and
the value of full is incremented because the producer has just
filled a slot in the buffer.
Producer & Consumer Problem
13
• Solution Consumer:
• The pseudo-code for the consumer function looks like this:
Producer & Consumer Problem
14
• Solution Consumer:
• The consumer waits until there is at least one full slot in
the buffer.
• Then it decrements the full semaphore because the
number of occupied slots will be decreased by one, after
the consumer completes its operation.
• After that, the consumer acquires lock on the buffer.
• Following that, the consumer completes the removal
operation so that the data from one of the full slots is
removed.
• Then, the consumer releases the lock.
• Finally, the empty semaphore is incremented by 1,
because the consumer has just removed data from an
occupied slot, thus making it empty.
Any Questions?
15

More Related Content

Similar to 1 Synchronization.pptx

MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptx
senthilkumar969017
 
Open source: Top issues in the top enterprise packages
Open source: Top issues in the top enterprise packagesOpen source: Top issues in the top enterprise packages
Open source: Top issues in the top enterprise packages
Rogue Wave Software
 
Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Mike Willbanks
 
cs1311lecture25wdl.ppt
cs1311lecture25wdl.pptcs1311lecture25wdl.ppt
cs1311lecture25wdl.ppt
FannyBellows
 
Async event based web server
Async event based web serverAsync event based web server
Async event based web server
Gi Woong Lee
 
Operating System Process Synchronization
Operating System Process SynchronizationOperating System Process Synchronization
Operating System Process Synchronization
Haziq Naeem
 
Adsa u4 ver 1.0
Adsa u4 ver 1.0Adsa u4 ver 1.0
Adsa u4 ver 1.0
Dr. C.V. Suresh Babu
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
Alex Moskvin
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
Jannet Peetz
 
Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014
Lari Hotari
 
Progress OE performance management
Progress OE performance managementProgress OE performance management
Progress OE performance managementYassine MOALLA
 
Progress Openedge performance management
Progress Openedge performance managementProgress Openedge performance management
Progress Openedge performance management
Yassine MOALLA
 
operating system
operating systemoperating system
operating system
Bhuridech Sudsee
 
Process management in Operating System_Unit-2
Process management in Operating System_Unit-2Process management in Operating System_Unit-2
Process management in Operating System_Unit-2
mohanaps
 
Real-World Load Testing of ADF Fusion Applications Demonstrated - Oracle Ope...
Real-World Load Testing of ADF Fusion Applications Demonstrated  - Oracle Ope...Real-World Load Testing of ADF Fusion Applications Demonstrated  - Oracle Ope...
Real-World Load Testing of ADF Fusion Applications Demonstrated - Oracle Ope...
Getting value from IoT, Integration and Data Analytics
 
Interactions complicate debugging
Interactions complicate debuggingInteractions complicate debugging
Interactions complicate debugging
Syed Zaid Irshad
 
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming ApplicationsMetrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
confluent
 
Putting Kafka Into Overdrive
Putting Kafka Into OverdrivePutting Kafka Into Overdrive
Putting Kafka Into Overdrive
Todd Palino
 
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.pptBIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
Kadri20
 

Similar to 1 Synchronization.pptx (20)

MODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptxMODULE 3 process synchronizationnnn.pptx
MODULE 3 process synchronizationnnn.pptx
 
Open source: Top issues in the top enterprise packages
Open source: Top issues in the top enterprise packagesOpen source: Top issues in the top enterprise packages
Open source: Top issues in the top enterprise packages
 
Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012Gearman - Northeast PHP 2012
Gearman - Northeast PHP 2012
 
cs1311lecture25wdl.ppt
cs1311lecture25wdl.pptcs1311lecture25wdl.ppt
cs1311lecture25wdl.ppt
 
Async event based web server
Async event based web serverAsync event based web server
Async event based web server
 
Operating System Process Synchronization
Operating System Process SynchronizationOperating System Process Synchronization
Operating System Process Synchronization
 
Adsa u4 ver 1.0
Adsa u4 ver 1.0Adsa u4 ver 1.0
Adsa u4 ver 1.0
 
Realtime traffic analyser
Realtime traffic analyserRealtime traffic analyser
Realtime traffic analyser
 
Performance Tuning
Performance TuningPerformance Tuning
Performance Tuning
 
Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014Performance tuning Grails applications SpringOne 2GX 2014
Performance tuning Grails applications SpringOne 2GX 2014
 
Progress OE performance management
Progress OE performance managementProgress OE performance management
Progress OE performance management
 
Progress Openedge performance management
Progress Openedge performance managementProgress Openedge performance management
Progress Openedge performance management
 
operating system
operating systemoperating system
operating system
 
Operating system
Operating systemOperating system
Operating system
 
Process management in Operating System_Unit-2
Process management in Operating System_Unit-2Process management in Operating System_Unit-2
Process management in Operating System_Unit-2
 
Real-World Load Testing of ADF Fusion Applications Demonstrated - Oracle Ope...
Real-World Load Testing of ADF Fusion Applications Demonstrated  - Oracle Ope...Real-World Load Testing of ADF Fusion Applications Demonstrated  - Oracle Ope...
Real-World Load Testing of ADF Fusion Applications Demonstrated - Oracle Ope...
 
Interactions complicate debugging
Interactions complicate debuggingInteractions complicate debugging
Interactions complicate debugging
 
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming ApplicationsMetrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
 
Putting Kafka Into Overdrive
Putting Kafka Into OverdrivePutting Kafka Into Overdrive
Putting Kafka Into Overdrive
 
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.pptBIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
BIL406-Chapter-9-Synchronization and Communication in MIMD Systems.ppt
 

More from AbuBakkarShayan

DLD PRESENTATION1.pptx
DLD PRESENTATION1.pptxDLD PRESENTATION1.pptx
DLD PRESENTATION1.pptx
AbuBakkarShayan
 
Critical Section Problem.pptx
Critical Section Problem.pptxCritical Section Problem.pptx
Critical Section Problem.pptx
AbuBakkarShayan
 
Deadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptxDeadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptx
AbuBakkarShayan
 
SRS.pdf
SRS.pdfSRS.pdf
Deadlock 4.pptx
Deadlock 4.pptxDeadlock 4.pptx
Deadlock 4.pptx
AbuBakkarShayan
 
OS Semaphore.pptx
OS Semaphore.pptxOS Semaphore.pptx
OS Semaphore.pptx
AbuBakkarShayan
 
dessler_ch1.ppt
dessler_ch1.pptdessler_ch1.ppt
dessler_ch1.ppt
AbuBakkarShayan
 
Area-12-Internal-and-External-Environment.ppt
Area-12-Internal-and-External-Environment.pptArea-12-Internal-and-External-Environment.ppt
Area-12-Internal-and-External-Environment.ppt
AbuBakkarShayan
 
Lesson 09.ppt
Lesson 09.pptLesson 09.ppt
Lesson 09.ppt
AbuBakkarShayan
 
Lecture #02 ECS-511.pptx
Lecture #02 ECS-511.pptxLecture #02 ECS-511.pptx
Lecture #02 ECS-511.pptx
AbuBakkarShayan
 

More from AbuBakkarShayan (10)

DLD PRESENTATION1.pptx
DLD PRESENTATION1.pptxDLD PRESENTATION1.pptx
DLD PRESENTATION1.pptx
 
Critical Section Problem.pptx
Critical Section Problem.pptxCritical Section Problem.pptx
Critical Section Problem.pptx
 
Deadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptxDeadlock Algorithms 3.pptx
Deadlock Algorithms 3.pptx
 
SRS.pdf
SRS.pdfSRS.pdf
SRS.pdf
 
Deadlock 4.pptx
Deadlock 4.pptxDeadlock 4.pptx
Deadlock 4.pptx
 
OS Semaphore.pptx
OS Semaphore.pptxOS Semaphore.pptx
OS Semaphore.pptx
 
dessler_ch1.ppt
dessler_ch1.pptdessler_ch1.ppt
dessler_ch1.ppt
 
Area-12-Internal-and-External-Environment.ppt
Area-12-Internal-and-External-Environment.pptArea-12-Internal-and-External-Environment.ppt
Area-12-Internal-and-External-Environment.ppt
 
Lesson 09.ppt
Lesson 09.pptLesson 09.ppt
Lesson 09.ppt
 
Lecture #02 ECS-511.pptx
Lecture #02 ECS-511.pptxLecture #02 ECS-511.pptx
Lecture #02 ECS-511.pptx
 

Recently uploaded

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 

Recently uploaded (20)

openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 

1 Synchronization.pptx

  • 2. Quick Recap of Previous Lecture • Software solution to the Critical Section Problem • Semaphore • Wait ( ) • Signal ( ) • Types of Semaphore • Counting semaphore • Binary semaphore • Advantages of semaphore 2
  • 3. Today’s Outlines • Process Synchronization • Synchronization Hardware • Mutex Lock • Classical Problems of Synchronization • Bounded Buffer (Producer-Consumer) Problem • Producer & Consumer Operation • Solve with help of Semaphore 3
  • 4. Process Synchronization • Process Synchronization is a way to coordinate processes that use shared data. • It occurs in an operating system among cooperating processes. While executing many concurrent processes, • Process synchronization helps to maintain shared data consistency and cooperating process execution. • Real World Example: • An example of synchronize is when army bands coordinate their musical instruments. • An example of synchronize is when you and a friend both set your watch to 12:15. 4
  • 5. Synchronization Hardware • Many systems provide hardware support for critical section Problem. • The critical section problem could be solved easily in a single- processor environment: • if we could disallow interrupts to occur while a shared variable or resource is being modified. • In this manner, we could be sure that the current sequence of instructions would be allowed to execute in order without pre- emption. • Unfortunately, this solution is not feasible in a multiprocessor environment. • Disabling interrupt on a multiprocessor environment can be time consuming as the message is passed to all the processors. • This message transmission lag, delays entry of threads into critical section and the system efficiency decreases. 5
  • 6. Mutex Lock • As the synchronization hardware solution is not easy to implement for everyone, a strict software approach called Mutex Locks was introduced. • In this approach, in the entry section of code: • A LOCK is acquired over the critical resources modified and used inside critical section, and in the exit section that LOCK is released. • As the resource is locked while a process executes its critical section hence no other process can access it. 6
  • 7. Classical Problems of Synchronization • We will discuss the following three problems: • Bounded Buffer (Producer-Consumer) Problem • Dining Philosophers Problem • The Readers Writers Problem • Bounded Buffer Problem (Producer-Consumer Problem) • Which is also called producer consumer problem, is one of the classic problems of synchronization. • Problem Statement: • There is a buffer of n slots and each slot is capable of storing one unit of data. • There are two processes running, namely, producer and consumer, which are operating on the buffer. 7
  • 8. Producer & Consumer Problem 8 • Producer & Consumer Problem: • A producer tries to insert data into an empty slot of the buffer. • A consumer tries to remove data from a filled slot in the buffer. • As you might have guessed by now, those two processes won’t produce the expected output if they are being executed concurrently. • There needs to be a way to make the producer and consumer work in an independent manner.
  • 9. Producer & Consumer Problem 9 • Solution: • One solution of this problem is to use semaphores. • The semaphores which will be used here are: • S, a binary semaphore which is used to acquire and release the lock. • empty, a counting semaphore whose initial value is the number of slots in the buffer, since, initially all slots are empty. • full, a counting semaphore whose initial value is 0. • At any instant, the current value of empty represents the number of empty slots in the buffer and full represents the number of occupied slots in the buffer.
  • 10. Producer & Consumer Problem 10 Semaphore: S = 1 Semaphore: Empty = n Semaphore: Full = 0
  • 11. Producer & Consumer Problem 11 • Solution Producer: • The pseudo-code of the producer function looks like this:
  • 12. Producer & Consumer Problem 12 • Solution for Producer: • we can see that a producer first waits until there is at least one empty slot. • Then it decrements the empty semaphore because, there will now be one less empty slot, since the producer is going to insert data in one of those slots. • Then, it acquires lock on the buffer, so that the consumer cannot access the buffer until producer completes its operation. • After performing the insert operation, the lock is released and the value of full is incremented because the producer has just filled a slot in the buffer.
  • 13. Producer & Consumer Problem 13 • Solution Consumer: • The pseudo-code for the consumer function looks like this:
  • 14. Producer & Consumer Problem 14 • Solution Consumer: • The consumer waits until there is at least one full slot in the buffer. • Then it decrements the full semaphore because the number of occupied slots will be decreased by one, after the consumer completes its operation. • After that, the consumer acquires lock on the buffer. • Following that, the consumer completes the removal operation so that the data from one of the full slots is removed. • Then, the consumer releases the lock. • Finally, the empty semaphore is incremented by 1, because the consumer has just removed data from an occupied slot, thus making it empty.