SlideShare a Scribd company logo
1 of 57
• In the Operating System, there are a number of
processes present in a particular state.
• At the same time, we have a limited amount of resources
present, so those resources need to be shared among
various processes.
• But you should make sure that no two processes are
using the same resource at the same time because this
may lead to data inconsistency.
• So, synchronization of process should be there in the
Operating System.
• Types of Process:
• Cooperative Processes
• Independent Processes
• These processes that are sharing resources between
each other are called Cooperative Processes.
• Example: Sharing Variable, memory, code, resources e.g.
Printer
• The processes whose execution does not affect the
execution of other processes are called Independent
Processes.
• Example: Banking Server Transaction, one Transaction
for SBI and another for HDFC.
• In an Operating System, we have a number of processes
and these processes require a number of resources.
• Now, think of a situation where we have two processes
and these processes are using the same variable "a".
They are reading the variable and then updating the
value of the variable and finally writing the data in the
memory.
• The code in the above part is accessed by all the process
and this can lead to data inconsistency.
• It means that in a group of cooperating processes, at a
given point of time, only one process must be executing
its critical section.
• If any other process also wants to execute its critical
section, it must wait until the first one finishes.
• Mutual Exclusion
• Progress
• Bounded Waiting
• If a process is in the
critical section, then
other processes
shouldn't be allowed
to enter into the
critical section at
that time i.e. there
must be some
mutual exclusion
between processes.
• Progress means that if
one process doesn't
need to execute into
critical section then it
should not stop other
processes to get into
the critical section.
• There must be some limit to the number of times a
process can go into the critical section i.e. there must be
some upper bound.
• If no upper bound is there then the same process will be
allowed to go into the critical section again and again and
other processes will never get a chance to get into the
critical section.
• Semaphore
• Binary and Counting Semaphore
• 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.
• The signal() function is used to increment the value of
the semaphore variable by one.
• Binary Semaphores
• Counting Semaphores
• In Binary semaphores, the value of the semaphore
variable will be 0 or 1.
• Initially, the value of semaphore variable is set to 1 and if
some process wants to use some resource then
the wait() function is called and the value of the
semaphore is changed to 0 from 1.
• The process then uses the resource and when it releases
the resource then the signal() function is called and the
value of the semaphore variable is increased to 1.
• If at a particular instant of time, the value of the
semaphore variable is 0 and some other process wants
to use the same resource then it has to wait for the
release of the resource by the previous process.
• In this way, process synchronization can be achieved.
• In Counting semaphores, firstly, the semaphore variable
is initialized with the number of resources available.
• After that, whenever a process needs some resource,
then the wait() function is called and the value of the
semaphore variable is decreased by one.
• The process then uses the resource and after using the
resource, the signal() function is called and the value of
the semaphore variable is increased by one.
• So, when the value of the semaphore variable goes to 0
i.e all the resources are taken by the process and there is
no resource left to be used, then if some other process
wants to use resources then that process has to wait for
its turn.
• In this way, we achieve the process synchronization.
Classical Problems of Process synchronization
• The Producer-Consumer problem is a classic
problem this is used for multi-process
synchronization i.e. synchronization between
more than one processes.
• Bounded buffer problem, is also called producer
consumer problem.
• In the producer-consumer problem, there is one Producer
that is producing something and there is one Consumer
that is consuming the products produced by the
Producer.
• The producers and consumers share the same memory
buffer that is of fixed-size.
• The job of the Producer is to generate the data,
put it into the buffer, and again start generating
data.
• While the job of the Consumer is to consume the
data from the buffer.
• The following are the problems that might occur in the
Producer-Consumer:
1. The producer should produce data only when the buffer
is not full. If the buffer is full, then the producer shouldn't
be allowed to put any data into the buffer.
2. The consumer should consume data only when the
buffer is not empty. If the buffer is empty, then the
consumer shouldn't be allowed to take any data from
the buffer.
3. The producer and consumer should not access the
buffer at the same time.
• The above three problems can be solved with the help of
semaphores. In the producer-consumer problem, we use three
semaphore variables:
• Semaphore S: This semaphore variable is used to achieve
mutual exclusion between processes. By using this variable,
either Producer or Consumer will be allowed to use or access
the shared buffer at a particular time. This variable is set to 1
initially.
• Semaphore E: This semaphore variable is used to define the
empty space in the buffer. Initially, it is set to the whole space
of the buffer i.e. "n" because the buffer is initially empty.
• Semaphore F: This semaphore variable is used to define the
space that is filled by the producer. Initially, it is set to "0"
because there is no space filled by the producer initially.
• By using the above three semaphore variables and by
using the wait() and signal() function.
• we can solve our problem the wait() function decreases
the semaphore variable by 1 and the signal() function
increases the semaphore variable by 1.
S- To achieve mutual exclusion between processes
E- Empty space in the buffer
F- Space that is filled by the producer
• The following Code for Consumer
• The dining philosophers problem is another classic
synchronization problem which is used to evaluate
situations where there is a need of allocating multiple
resources to multiple processes.
• Consider there are five philosophers sitting around a
circular dining table. The dining table has five chopsticks
and a bowl of rice or Noodles in the middle as shown in
the below figure.
• There is one chopstick between each philosopher
• A philosopher must pick up its two nearest chopsticks in
order to eat
• A philosopher must pick up first one chopstick, then the
second one, not both at once
• The dining philosophers problem states
that there are 5 philosophers sharing a
circular table and they eat and think
alternatively.
• There is a bowl of rice for each of the
philosophers and 5 chopsticks.
• A philosopher needs both their right and
left chopstick to eat.
• A hungry philosopher may only eat if
there are both chopsticks available.
• Otherwise a philosopher puts down their
chopstick and begin thinking again.
• The dining philosopher is a classic
synchronization problem as it
demonstrates a large class of
concurrency control problems.
• A solution of the Dining Philosophers
Problem is to use a semaphore to
represent a chopstick. A chopstick can be
picked up by executing a wait operation
on the semaphore and released by
executing a signal semaphore.
•
The structure of the chopstick is shown
below:
• semaphore chopstick [5];
• Initially the elements of the chopstick are
initialized to 1 as the chopsticks are on the
table and not picked up by a philosopher.
• In the above structure, first wait
operation is performed on
chopstick[i] and chopstick[ (i+1) %
5]. This means that the
philosopher i has picked up the
chopsticks on his sides. Then the
eating function is performed.
• After that, signal operation is
performed on chopstick[i] and
chopstick[ (i+1) % 5]. This means
that the philosopher i has eaten
and put down the chopsticks on
his sides.
• Then the philosopher goes back to
thinking.
• Difficulty with the solution
• The above solution makes sure that no two neighboring
philosophers can eat at the same time. But this solution
can lead to a deadlock.
• This may happen if all the philosophers pick their left
chopstick simultaneously. Then none of them can eat and
deadlock occurs.
• Some of the ways to avoid deadlock are as follows:
1. There should be at most four philosophers on the
table.
2. An even philosopher should pick the right chopstick
and then the left chopstick while an odd philosopher
should pick the left chopstick and then the right
chopstick.
• Monitor concepts by presenting a deadlock-free solution
to the dining-philosophers problem.
• Monitor is used to control access to state variables and
condition variables.
• It only tells when to enter and exit the segment.
• This solution imposes the restriction that a philosopher
may pick up her chopsticks only if both of them are
available.
• we introduce the following data structure:
• THINKING – When philosopher doesn’t want to gain
access to either fork.
• HUNGRY – When philosopher wants to enter the critical
section.
• EATING – When philosopher has got both the forks, i.e.,
he has entered the section.
• https://www.tutorialspoint.com/readers-writers-
problem

More Related Content

Similar to Process cooperation and synchronisation

ICPSR - Complex Systems Computing - Session 7 - 2012
ICPSR - Complex Systems Computing - Session 7 - 2012ICPSR - Complex Systems Computing - Session 7 - 2012
ICPSR - Complex Systems Computing - Session 7 - 2012Daniel Katz
 
Inter process communication
Inter process communicationInter process communication
Inter process communicationGift Kaliza
 
Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...
Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...
Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...Ontico
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.pptjayverma27
 
Operating system 06 operating system classification
Operating system 06 operating system classificationOperating system 06 operating system classification
Operating system 06 operating system classificationVaibhav Khanna
 
Lecture 5 process synchronization
Lecture 5 process synchronizationLecture 5 process synchronization
Lecture 5 process synchronizationKlintonChhun
 
Dining Philosopher Problem and Solution
Dining Philosopher Problem and SolutionDining Philosopher Problem and Solution
Dining Philosopher Problem and SolutionLahiru Danushka
 
3.6 Deadlock-operating system unit 3.pptx
3.6 Deadlock-operating system unit 3.pptx3.6 Deadlock-operating system unit 3.pptx
3.6 Deadlock-operating system unit 3.pptxsvulasal
 
Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2DanWooster1
 
Asynchronous Apex .pptx
Asynchronous Apex .pptxAsynchronous Apex .pptx
Asynchronous Apex .pptxKadharBashaJ
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronizationlodhran-hayat
 
Operating system 07 batch processing operating system
Operating system 07 batch processing operating systemOperating system 07 batch processing operating system
Operating system 07 batch processing operating systemVaibhav Khanna
 

Similar to Process cooperation and synchronisation (20)

Deadlock 4.pptx
Deadlock 4.pptxDeadlock 4.pptx
Deadlock 4.pptx
 
Ch5 process synchronization
Ch5   process synchronizationCh5   process synchronization
Ch5 process synchronization
 
ICPSR - Complex Systems Computing - Session 7 - 2012
ICPSR - Complex Systems Computing - Session 7 - 2012ICPSR - Complex Systems Computing - Session 7 - 2012
ICPSR - Complex Systems Computing - Session 7 - 2012
 
Inter process communication
Inter process communicationInter process communication
Inter process communication
 
Semaphore
SemaphoreSemaphore
Semaphore
 
Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...
Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...
Efficient cluster resource management by using Cook and Mesos / Li Jin (Two S...
 
Critical section operating system
Critical section  operating systemCritical section  operating system
Critical section operating system
 
Fuzzy logic
Fuzzy logicFuzzy logic
Fuzzy logic
 
Process Synchronization -1.ppt
Process Synchronization -1.pptProcess Synchronization -1.ppt
Process Synchronization -1.ppt
 
Operating system 06 operating system classification
Operating system 06 operating system classificationOperating system 06 operating system classification
Operating system 06 operating system classification
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
Lecture 5 process synchronization
Lecture 5 process synchronizationLecture 5 process synchronization
Lecture 5 process synchronization
 
Implementation
ImplementationImplementation
Implementation
 
Dining Philosopher Problem and Solution
Dining Philosopher Problem and SolutionDining Philosopher Problem and Solution
Dining Philosopher Problem and Solution
 
3.6 Deadlock-operating system unit 3.pptx
3.6 Deadlock-operating system unit 3.pptx3.6 Deadlock-operating system unit 3.pptx
3.6 Deadlock-operating system unit 3.pptx
 
Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2Java Chapter 05 - Conditions & Loops: part 2
Java Chapter 05 - Conditions & Loops: part 2
 
Deadlock.ppt
Deadlock.pptDeadlock.ppt
Deadlock.ppt
 
Asynchronous Apex .pptx
Asynchronous Apex .pptxAsynchronous Apex .pptx
Asynchronous Apex .pptx
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Operating system 07 batch processing operating system
Operating system 07 batch processing operating systemOperating system 07 batch processing operating system
Operating system 07 batch processing operating system
 

More from JayeshGadhave1

production-170629054926 (1) production system
production-170629054926 (1) production systemproduction-170629054926 (1) production system
production-170629054926 (1) production systemJayeshGadhave1
 
Threat intelligence life cycle steps by steps
Threat intelligence life cycle steps by stepsThreat intelligence life cycle steps by steps
Threat intelligence life cycle steps by stepsJayeshGadhave1
 
C_02_BME_34_41_50_57_60 non contact temprature detection
C_02_BME_34_41_50_57_60 non contact temprature detectionC_02_BME_34_41_50_57_60 non contact temprature detection
C_02_BME_34_41_50_57_60 non contact temprature detectionJayeshGadhave1
 
autocollometer Mechanical engineering project
autocollometer Mechanical engineering projectautocollometer Mechanical engineering project
autocollometer Mechanical engineering projectJayeshGadhave1
 
74351a41-b6ff-4739-99d9-ff5ad260914c.pptx
74351a41-b6ff-4739-99d9-ff5ad260914c.pptx74351a41-b6ff-4739-99d9-ff5ad260914c.pptx
74351a41-b6ff-4739-99d9-ff5ad260914c.pptxJayeshGadhave1
 
Data modelling it's process and examples
Data modelling it's process and examplesData modelling it's process and examples
Data modelling it's process and examplesJayeshGadhave1
 
Templet for digital poster-Sec-D.pptx
Templet for digital poster-Sec-D.pptxTemplet for digital poster-Sec-D.pptx
Templet for digital poster-Sec-D.pptxJayeshGadhave1
 
Unit 2_OS process management
Unit 2_OS process management Unit 2_OS process management
Unit 2_OS process management JayeshGadhave1
 
Unit 1_Operating system
Unit 1_Operating system Unit 1_Operating system
Unit 1_Operating system JayeshGadhave1
 
Peizo electric effect
Peizo electric effect Peizo electric effect
Peizo electric effect JayeshGadhave1
 

More from JayeshGadhave1 (16)

production-170629054926 (1) production system
production-170629054926 (1) production systemproduction-170629054926 (1) production system
production-170629054926 (1) production system
 
Threat intelligence life cycle steps by steps
Threat intelligence life cycle steps by stepsThreat intelligence life cycle steps by steps
Threat intelligence life cycle steps by steps
 
C_02_BME_34_41_50_57_60 non contact temprature detection
C_02_BME_34_41_50_57_60 non contact temprature detectionC_02_BME_34_41_50_57_60 non contact temprature detection
C_02_BME_34_41_50_57_60 non contact temprature detection
 
autocollometer Mechanical engineering project
autocollometer Mechanical engineering projectautocollometer Mechanical engineering project
autocollometer Mechanical engineering project
 
74351a41-b6ff-4739-99d9-ff5ad260914c.pptx
74351a41-b6ff-4739-99d9-ff5ad260914c.pptx74351a41-b6ff-4739-99d9-ff5ad260914c.pptx
74351a41-b6ff-4739-99d9-ff5ad260914c.pptx
 
Data modelling it's process and examples
Data modelling it's process and examplesData modelling it's process and examples
Data modelling it's process and examples
 
Templet for digital poster-Sec-D.pptx
Templet for digital poster-Sec-D.pptxTemplet for digital poster-Sec-D.pptx
Templet for digital poster-Sec-D.pptx
 
Regression
Regression Regression
Regression
 
productlifecycle
productlifecycleproductlifecycle
productlifecycle
 
Lisa_Chang.ppt
Lisa_Chang.pptLisa_Chang.ppt
Lisa_Chang.ppt
 
Unit 2_OS process management
Unit 2_OS process management Unit 2_OS process management
Unit 2_OS process management
 
Unit 1_Operating system
Unit 1_Operating system Unit 1_Operating system
Unit 1_Operating system
 
Peizo electric effect
Peizo electric effect Peizo electric effect
Peizo electric effect
 
pptonboilers.pdf
pptonboilers.pdfpptonboilers.pdf
pptonboilers.pdf
 
Sorting techniques
Sorting techniques Sorting techniques
Sorting techniques
 
cryptography.pdf
cryptography.pdfcryptography.pdf
cryptography.pdf
 

Recently uploaded

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 

Recently uploaded (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 

Process cooperation and synchronisation

  • 1.
  • 2. • In the Operating System, there are a number of processes present in a particular state. • At the same time, we have a limited amount of resources present, so those resources need to be shared among various processes. • But you should make sure that no two processes are using the same resource at the same time because this may lead to data inconsistency.
  • 3. • So, synchronization of process should be there in the Operating System. • Types of Process: • Cooperative Processes • Independent Processes
  • 4. • These processes that are sharing resources between each other are called Cooperative Processes. • Example: Sharing Variable, memory, code, resources e.g. Printer • The processes whose execution does not affect the execution of other processes are called Independent Processes. • Example: Banking Server Transaction, one Transaction for SBI and another for HDFC.
  • 5.
  • 6. • In an Operating System, we have a number of processes and these processes require a number of resources. • Now, think of a situation where we have two processes and these processes are using the same variable "a". They are reading the variable and then updating the value of the variable and finally writing the data in the memory.
  • 7. • The code in the above part is accessed by all the process and this can lead to data inconsistency. • It means that in a group of cooperating processes, at a given point of time, only one process must be executing its critical section. • If any other process also wants to execute its critical section, it must wait until the first one finishes.
  • 8.
  • 9. • Mutual Exclusion • Progress • Bounded Waiting
  • 10. • If a process is in the critical section, then other processes shouldn't be allowed to enter into the critical section at that time i.e. there must be some mutual exclusion between processes.
  • 11. • Progress means that if one process doesn't need to execute into critical section then it should not stop other processes to get into the critical section.
  • 12. • There must be some limit to the number of times a process can go into the critical section i.e. there must be some upper bound. • If no upper bound is there then the same process will be allowed to go into the critical section again and again and other processes will never get a chance to get into the critical section.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. • Semaphore • Binary and Counting Semaphore
  • 21. • 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.
  • 22. • 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.
  • 23. • 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.
  • 24. • The signal() function is used to increment the value of the semaphore variable by one.
  • 25. • Binary Semaphores • Counting Semaphores
  • 26. • In Binary semaphores, the value of the semaphore variable will be 0 or 1. • Initially, the value of semaphore variable is set to 1 and if some process wants to use some resource then the wait() function is called and the value of the semaphore is changed to 0 from 1. • The process then uses the resource and when it releases the resource then the signal() function is called and the value of the semaphore variable is increased to 1. • If at a particular instant of time, the value of the semaphore variable is 0 and some other process wants to use the same resource then it has to wait for the release of the resource by the previous process. • In this way, process synchronization can be achieved.
  • 27. • In Counting semaphores, firstly, the semaphore variable is initialized with the number of resources available. • After that, whenever a process needs some resource, then the wait() function is called and the value of the semaphore variable is decreased by one. • The process then uses the resource and after using the resource, the signal() function is called and the value of the semaphore variable is increased by one. • So, when the value of the semaphore variable goes to 0 i.e all the resources are taken by the process and there is no resource left to be used, then if some other process wants to use resources then that process has to wait for its turn. • In this way, we achieve the process synchronization.
  • 28. Classical Problems of Process synchronization
  • 29. • The Producer-Consumer problem is a classic problem this is used for multi-process synchronization i.e. synchronization between more than one processes. • Bounded buffer problem, is also called producer consumer problem.
  • 30. • In the producer-consumer problem, there is one Producer that is producing something and there is one Consumer that is consuming the products produced by the Producer. • The producers and consumers share the same memory buffer that is of fixed-size.
  • 31. • The job of the Producer is to generate the data, put it into the buffer, and again start generating data. • While the job of the Consumer is to consume the data from the buffer.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39. • The following are the problems that might occur in the Producer-Consumer: 1. The producer should produce data only when the buffer is not full. If the buffer is full, then the producer shouldn't be allowed to put any data into the buffer. 2. The consumer should consume data only when the buffer is not empty. If the buffer is empty, then the consumer shouldn't be allowed to take any data from the buffer. 3. The producer and consumer should not access the buffer at the same time.
  • 40. • The above three problems can be solved with the help of semaphores. In the producer-consumer problem, we use three semaphore variables: • Semaphore S: This semaphore variable is used to achieve mutual exclusion between processes. By using this variable, either Producer or Consumer will be allowed to use or access the shared buffer at a particular time. This variable is set to 1 initially. • Semaphore E: This semaphore variable is used to define the empty space in the buffer. Initially, it is set to the whole space of the buffer i.e. "n" because the buffer is initially empty. • Semaphore F: This semaphore variable is used to define the space that is filled by the producer. Initially, it is set to "0" because there is no space filled by the producer initially.
  • 41. • By using the above three semaphore variables and by using the wait() and signal() function. • we can solve our problem the wait() function decreases the semaphore variable by 1 and the signal() function increases the semaphore variable by 1.
  • 42. S- To achieve mutual exclusion between processes E- Empty space in the buffer F- Space that is filled by the producer
  • 43. • The following Code for Consumer
  • 44. • The dining philosophers problem is another classic synchronization problem which is used to evaluate situations where there is a need of allocating multiple resources to multiple processes.
  • 45. • Consider there are five philosophers sitting around a circular dining table. The dining table has five chopsticks and a bowl of rice or Noodles in the middle as shown in the below figure.
  • 46. • There is one chopstick between each philosopher • A philosopher must pick up its two nearest chopsticks in order to eat • A philosopher must pick up first one chopstick, then the second one, not both at once
  • 47. • The dining philosophers problem states that there are 5 philosophers sharing a circular table and they eat and think alternatively. • There is a bowl of rice for each of the philosophers and 5 chopsticks. • A philosopher needs both their right and left chopstick to eat. • A hungry philosopher may only eat if there are both chopsticks available. • Otherwise a philosopher puts down their chopstick and begin thinking again. • The dining philosopher is a classic synchronization problem as it demonstrates a large class of concurrency control problems.
  • 48. • A solution of the Dining Philosophers Problem is to use a semaphore to represent a chopstick. A chopstick can be picked up by executing a wait operation on the semaphore and released by executing a signal semaphore. • The structure of the chopstick is shown below: • semaphore chopstick [5]; • Initially the elements of the chopstick are initialized to 1 as the chopsticks are on the table and not picked up by a philosopher.
  • 49.
  • 50. • In the above structure, first wait operation is performed on chopstick[i] and chopstick[ (i+1) % 5]. This means that the philosopher i has picked up the chopsticks on his sides. Then the eating function is performed. • After that, signal operation is performed on chopstick[i] and chopstick[ (i+1) % 5]. This means that the philosopher i has eaten and put down the chopsticks on his sides. • Then the philosopher goes back to thinking.
  • 51. • Difficulty with the solution • The above solution makes sure that no two neighboring philosophers can eat at the same time. But this solution can lead to a deadlock. • This may happen if all the philosophers pick their left chopstick simultaneously. Then none of them can eat and deadlock occurs. • Some of the ways to avoid deadlock are as follows: 1. There should be at most four philosophers on the table. 2. An even philosopher should pick the right chopstick and then the left chopstick while an odd philosopher should pick the left chopstick and then the right chopstick.
  • 52. • Monitor concepts by presenting a deadlock-free solution to the dining-philosophers problem. • Monitor is used to control access to state variables and condition variables. • It only tells when to enter and exit the segment. • This solution imposes the restriction that a philosopher may pick up her chopsticks only if both of them are available.
  • 53. • we introduce the following data structure: • THINKING – When philosopher doesn’t want to gain access to either fork. • HUNGRY – When philosopher wants to enter the critical section. • EATING – When philosopher has got both the forks, i.e., he has entered the section.
  • 54.
  • 55.
  • 56.