SlideShare a Scribd company logo
Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Chapter 5: Process
Synchronization
5.2 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Chapter 5: Process Synchronization
 Background
 The Critical-Section Problem
 Peterson’s Solution
 Synchronization Hardware
 Mutex Locks
 Semaphores
 Classic Problems of Synchronization
 Monitors
 Synchronization Examples
 Alternative Approaches
5.3 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Objectives
 To present the concept of process synchronization.
 To introduce the critical-section problem, whose solutions
can be used to ensure the consistency of shared data
 To present both software and hardware solutions of the
critical-section problem
 To examine several classical process-synchronization
problems
 To explore several tools that are used to solve process
synchronization problems
5.4 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Background
 Processes can execute concurrently
 May be interrupted at any time, partially completing
execution
 Concurrent access to shared data may result in data
inconsistency
 Maintaining data consistency requires mechanisms to ensure
the orderly execution of cooperating processes
 Illustration of the problem:
Suppose that we wanted to provide a solution to the
consumer-producer problem that fills all the buffers. We can
do so by having an integer counter that keeps track of the
number of full buffers. Initially, counter is set to 0. It is
incremented by the producer after it produces a new buffer
and is decremented by the consumer after it consumes a
buffer.
5.5 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Critical Section Problem
 The critical section is a code segment where the shared
variables can be accessed. An atomic action is required in
a critical section i.e. only one process can execute in
its critical section at a time.
 Consider system of n processes {p0, p1, … pn-1}
 Each process has critical section segment of code
 Process may be changing common variables, updating
table, writing file, etc
 When one process in critical section, no other may be in its
critical section
 Critical section problem is to design protocol to solve this
 Each process must ask permission to enter critical section in
entry section, may follow critical section with exit section,
then remainder section
5.6 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Critical Section
 General structure of process Pi
5.7 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Solution to Critical-Section Problem
1. Mutual Exclusion - If process Pi is executing in its critical
section, then no other processes can be executing in their
critical sections
2. Progress - If no process is executing in its critical section and
there exist some processes that wish to enter their critical
section, then the selection of the processes that will enter the
critical section next cannot be postponed indefinitely
3. Bounded Waiting - A bound must exist on the number of
times that other processes are allowed to enter their critical
sections after a process has made a request to enter its critical
section and before that request is granted
 Assume that each process executes at a nonzero speed
 No assumption concerning relative speed of the n
processes
5.8 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Critical-Section Handling in OS
Two approaches depending on if kernel is preemptive or non-
preemptive
 Preemptive – allows preemption of process when running
in kernel mode
 Non-preemptive – runs until exits kernel mode, blocks, or
voluntarily yields CPU
Essentially free of race conditions in kernel mode
5.9 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Synchronization Hardware
 Many systems provide hardware support for implementing the
critical section code.
 All solutions below based on idea of locking
 Protecting critical regions via locks
 Uniprocessors – could disable interrupts
 Currently running code would execute without preemption
 Generally too inefficient on multiprocessor systems
 Operating systems using this not broadly scalable
 Modern machines provide special atomic hardware instructions
 Atomic = non-interruptible
5.10 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Solution to Critical-section Problem Using Locks
do {
acquire lock
critical section
release lock
remainder section
} while (TRUE);
5.11 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Mutex Locks
 Previous solutions are complicated and generally inaccessible
to application programmers
 OS designers build software tools to solve critical section
problem
 Simplest is mutex lock
 Protect a critical section by first acquire() a lock then
release() the lock
 Boolean variable indicating if lock is available or not
 Calls to acquire() and release() must be atomic
 Usually implemented via hardware atomic instructions
 But this solution requires busy waiting
 This lock therefore called a spinlock
5.12 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Semaphore
 Semaphores are integer variables that are used to solve the critical section
problem by using two atomic operations, wait and signal that are used for process
synchronization.
 The definitions of wait and signal are as follows −
 Wait The wait operation decrements the value of its argument S, if it is positive. If
S is negative or zero, then no operation is performed.
 wait(S)
 {
 while (S<=0);
 S--;
 }
 Signal The signal operation increments the value of its argument S.
 signal(S)
 {
 S++;
 }
5.13 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Types of Semaphores
 There are two main types of semaphores i.e. counting semaphores and
binary semaphores. Details about these are given as follows −
 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.
 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.
5.14 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Semaphore Implementation
 Must guarantee that no two processes can execute the wait()
and signal() on the same semaphore at the same time
 Thus, the implementation becomes the critical section problem
where the wait and signal code are placed in the critical
section
 Could now have busy waiting in critical section
implementation
 But implementation code is short
 Little busy waiting if critical section rarely occupied
 Note that applications may spend lots of time in critical sections
and therefore this is not a good solution
5.15 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Deadlock and Starvation
 Deadlock – two or more processes are waiting indefinitely for an
event that can be caused by only one of the waiting processes
 Let S and Q be two semaphores initialized to 1
P0 P1
wait(S); wait(Q);
wait(Q); wait(S);
... ...
signal(S); signal(Q);
signal(Q); signal(S);
 Starvation – indefinite blocking
 A process may never be removed from the semaphore queue in which it is
suspended
 Priority Inversion – Scheduling problem when lower-priority process
holds a lock needed by higher-priority process
 Solved via priority-inheritance protocol
5.16 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Classical Problems of Synchronization
 Semaphore can be used in other synchronization problems besides
Mutual Exclusion.
 Below are some of the classical problem depicting flaws of process
synchronaization in systems where cooperating processes are
present.
 We will discuss the following three problems:
 Bounded Buffer (Producer-Consumer) Problem
 Dining Philosophers Problem
 The Readers Writers Problem
5.17 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Bounded-Buffer Problem
 This problem is generalised in terms of the Producer
Consumer problem, where a finite buffer pool is used to
exchange messages between producer and consumer
processes.
 Because the buffer pool has a maximum size, this problem
is often called the Bounded buffer problem.
 Solution to this problem is, creating two counting
semaphores "full" and "empty" to keep track of the current
number of full and empty buffers respectively.
5.18 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
Dining Philosophers Problem
 The dining philosopher's problem involves the allocation of limited resources
to a group of processes in a deadlock-free and starvation-free manner.
5.19 Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
The Readers Writers Problem
 In this problem there are some processes(called readers) that only read the
shared data, and never change it, and there are other
processes(called writers) who may change the data in addition to reading,
or instead of reading it.
Silberschatz, Galvin and Gagne ©2013
Operating System Concepts – 9th Edition
End of Chapter 5

More Related Content

What's hot

CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
usmankiyani1
 
Ch1-Operating System Concept
Ch1-Operating System ConceptCh1-Operating System Concept
Ch1-Operating System Concept
Muhammad Bilal Tariq
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
Dr. Loganathan R
 
Chapter 3: Processes
Chapter 3: ProcessesChapter 3: Processes
Chapter 3: Processes
Shafaan Khaliq Bhatti
 
Operating System 3
Operating System 3Operating System 3
Operating System 3tech2click
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
Riya Choudhary
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
cscarcas
 
Memory : operating system ( Btech cse )
Memory : operating system ( Btech cse )Memory : operating system ( Btech cse )
Memory : operating system ( Btech cse )
HimanshuSharma1389
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationWayne Jones Jnr
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
Arnav Chowdhury
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-GalvinSonali Chauhan
 
Chapter 2: Operating System Structures
Chapter 2: Operating System StructuresChapter 2: Operating System Structures
Chapter 2: Operating System Structures
Shafaan Khaliq Bhatti
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
Dwight Sabio
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
Wayne Jones Jnr
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
Mukesh Chinta
 
Os services
Os servicesOs services
Os services
anilkumar_mca
 
Chapter 8 Operating Systems silberschatz : deadlocks
Chapter 8 Operating Systems silberschatz : deadlocksChapter 8 Operating Systems silberschatz : deadlocks
Chapter 8 Operating Systems silberschatz : deadlocks
GiulianoRanauro
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
hashim102
 

What's hot (20)

CPU Scheduling in OS Presentation
CPU Scheduling in OS  PresentationCPU Scheduling in OS  Presentation
CPU Scheduling in OS Presentation
 
Ch1-Operating System Concept
Ch1-Operating System ConceptCh1-Operating System Concept
Ch1-Operating System Concept
 
5 Process Scheduling
5 Process Scheduling5 Process Scheduling
5 Process Scheduling
 
Chapter 3: Processes
Chapter 3: ProcessesChapter 3: Processes
Chapter 3: Processes
 
Operating System 3
Operating System 3Operating System 3
Operating System 3
 
Process scheduling
Process schedulingProcess scheduling
Process scheduling
 
Unit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process SynchronizationUnit II - 3 - Operating System - Process Synchronization
Unit II - 3 - Operating System - Process Synchronization
 
Memory : operating system ( Btech cse )
Memory : operating system ( Btech cse )Memory : operating system ( Btech cse )
Memory : operating system ( Btech cse )
 
Chapter 6 - Process Synchronization
Chapter 6 - Process SynchronizationChapter 6 - Process Synchronization
Chapter 6 - Process Synchronization
 
Os unit 3 , process management
Os unit 3 , process managementOs unit 3 , process management
Os unit 3 , process management
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
Chapter 2: Operating System Structures
Chapter 2: Operating System StructuresChapter 2: Operating System Structures
Chapter 2: Operating System Structures
 
CPU scheduling ppt file
CPU scheduling ppt fileCPU scheduling ppt file
CPU scheduling ppt file
 
operating system structure
operating system structureoperating system structure
operating system structure
 
Chapter 7 - Deadlocks
Chapter 7 - DeadlocksChapter 7 - Deadlocks
Chapter 7 - Deadlocks
 
Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)Process scheduling (CPU Scheduling)
Process scheduling (CPU Scheduling)
 
Os services
Os servicesOs services
Os services
 
Chapter 8 Operating Systems silberschatz : deadlocks
Chapter 8 Operating Systems silberschatz : deadlocksChapter 8 Operating Systems silberschatz : deadlocks
Chapter 8 Operating Systems silberschatz : deadlocks
 
cpu scheduling
cpu schedulingcpu scheduling
cpu scheduling
 
Cpu scheduling
Cpu schedulingCpu scheduling
Cpu scheduling
 

Similar to 5 process synchronization

ch5 [Autosaved].ppt
ch5 [Autosaved].pptch5 [Autosaved].ppt
ch5 [Autosaved].ppt
monirJihad2
 
Operating System-Process Synchronization
Operating System-Process SynchronizationOperating System-Process Synchronization
Operating System-Process Synchronization
bismahmalik22
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
RohitPaul71
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
Ahmad Alarbeed
 
process synchronisation operating system
process synchronisation operating systemprocess synchronisation operating system
process synchronisation operating system
codefast
 
Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )
HimanshuSharma1389
 
chapter4.pptx
chapter4.pptxchapter4.pptx
chapter4.pptx
alisou77666
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
vijay974055
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
karinaabyys
 
ch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdfch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdf
sharada3
 
ch5.ppt operating system
ch5.ppt operating systemch5.ppt operating system
ch5.ppt operating system
Sami Mughal
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
K Gowsic Gowsic
 
chapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio pptchapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio ppt
Abdikani34
 
تعليم البرمجه.pdf
تعليم البرمجه.pdfتعليم البرمجه.pdf
تعليم البرمجه.pdf
ssuser893014
 
Operating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatzOperating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatz
GiulianoRanauro
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
MaxJoker2
 
Process Synchronisation Operating System
Process Synchronisation Operating SystemProcess Synchronisation Operating System
Process Synchronisation Operating System
DRAnithaSofiaLizCSES
 
05-Process-Synchronization.pdf
05-Process-Synchronization.pdf05-Process-Synchronization.pdf
05-Process-Synchronization.pdf
milisjojo
 
ch5.ppt Operating System Ppt for ptu student
ch5.ppt Operating System Ppt for ptu studentch5.ppt Operating System Ppt for ptu student
ch5.ppt Operating System Ppt for ptu student
BhartiRani14
 

Similar to 5 process synchronization (20)

ch5 [Autosaved].ppt
ch5 [Autosaved].pptch5 [Autosaved].ppt
ch5 [Autosaved].ppt
 
Operating System-Process Synchronization
Operating System-Process SynchronizationOperating System-Process Synchronization
Operating System-Process Synchronization
 
ch05.ppt
ch05.pptch05.ppt
ch05.ppt
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
process synchronisation operating system
process synchronisation operating systemprocess synchronisation operating system
process synchronisation operating system
 
Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )Process synchonization : operating system ( Btech cse )
Process synchonization : operating system ( Btech cse )
 
chapter4.pptx
chapter4.pptxchapter4.pptx
chapter4.pptx
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
ch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdfch5-Process_Synchronization.pdf
ch5-Process_Synchronization.pdf
 
ch5.ppt operating system
ch5.ppt operating systemch5.ppt operating system
ch5.ppt operating system
 
Process Synchronization
Process SynchronizationProcess Synchronization
Process Synchronization
 
chapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio pptchapter5 processes of synchronizatio ppt
chapter5 processes of synchronizatio ppt
 
تعليم البرمجه.pdf
تعليم البرمجه.pdfتعليم البرمجه.pdf
تعليم البرمجه.pdf
 
Operating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatzOperating Systems Chapter 6 silberschatz
Operating Systems Chapter 6 silberschatz
 
ch6.ppt
ch6.pptch6.ppt
ch6.ppt
 
Process Synchronisation Operating System
Process Synchronisation Operating SystemProcess Synchronisation Operating System
Process Synchronisation Operating System
 
05-Process-Synchronization.pdf
05-Process-Synchronization.pdf05-Process-Synchronization.pdf
05-Process-Synchronization.pdf
 
ch5.ppt Operating System Ppt for ptu student
ch5.ppt Operating System Ppt for ptu studentch5.ppt Operating System Ppt for ptu student
ch5.ppt Operating System Ppt for ptu student
 
ch6-1.ppt
ch6-1.pptch6-1.ppt
ch6-1.ppt
 

More from BaliThorat1

Lec15 sfm
Lec15 sfmLec15 sfm
Lec15 sfm
BaliThorat1
 
Lec14 multiview stereo
Lec14 multiview stereoLec14 multiview stereo
Lec14 multiview stereo
BaliThorat1
 
Lec13 stereo converted
Lec13 stereo convertedLec13 stereo converted
Lec13 stereo converted
BaliThorat1
 
Lec12 epipolar
Lec12 epipolarLec12 epipolar
Lec12 epipolar
BaliThorat1
 
Lec11 single view-converted
Lec11 single view-convertedLec11 single view-converted
Lec11 single view-converted
BaliThorat1
 
Lec10 alignment
Lec10 alignmentLec10 alignment
Lec10 alignment
BaliThorat1
 
Lec09 hough
Lec09 houghLec09 hough
Lec09 hough
BaliThorat1
 
Lec08 fitting
Lec08 fittingLec08 fitting
Lec08 fitting
BaliThorat1
 
8 operating system concept
8 operating system concept8 operating system concept
8 operating system concept
BaliThorat1
 
7 processor
7 processor7 processor
7 processor
BaliThorat1
 
6 input output devices
6 input output devices6 input output devices
6 input output devices
BaliThorat1
 
2 windows operating system
2 windows operating system2 windows operating system
2 windows operating system
BaliThorat1
 
5 computer memory
5 computer memory5 computer memory
5 computer memory
BaliThorat1
 
4 computer languages
4 computer languages4 computer languages
4 computer languages
BaliThorat1
 
1 fundamentals of computer
1 fundamentals of computer1 fundamentals of computer
1 fundamentals of computer
BaliThorat1
 
1 fundamentals of computer system
1 fundamentals of computer system1 fundamentals of computer system
1 fundamentals of computer system
BaliThorat1
 
Computer generation and classification
Computer generation and classificationComputer generation and classification
Computer generation and classification
BaliThorat1
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
BaliThorat1
 
6 cpu scheduling
6 cpu scheduling6 cpu scheduling
6 cpu scheduling
BaliThorat1
 
4 threads
4 threads4 threads
4 threads
BaliThorat1
 

More from BaliThorat1 (20)

Lec15 sfm
Lec15 sfmLec15 sfm
Lec15 sfm
 
Lec14 multiview stereo
Lec14 multiview stereoLec14 multiview stereo
Lec14 multiview stereo
 
Lec13 stereo converted
Lec13 stereo convertedLec13 stereo converted
Lec13 stereo converted
 
Lec12 epipolar
Lec12 epipolarLec12 epipolar
Lec12 epipolar
 
Lec11 single view-converted
Lec11 single view-convertedLec11 single view-converted
Lec11 single view-converted
 
Lec10 alignment
Lec10 alignmentLec10 alignment
Lec10 alignment
 
Lec09 hough
Lec09 houghLec09 hough
Lec09 hough
 
Lec08 fitting
Lec08 fittingLec08 fitting
Lec08 fitting
 
8 operating system concept
8 operating system concept8 operating system concept
8 operating system concept
 
7 processor
7 processor7 processor
7 processor
 
6 input output devices
6 input output devices6 input output devices
6 input output devices
 
2 windows operating system
2 windows operating system2 windows operating system
2 windows operating system
 
5 computer memory
5 computer memory5 computer memory
5 computer memory
 
4 computer languages
4 computer languages4 computer languages
4 computer languages
 
1 fundamentals of computer
1 fundamentals of computer1 fundamentals of computer
1 fundamentals of computer
 
1 fundamentals of computer system
1 fundamentals of computer system1 fundamentals of computer system
1 fundamentals of computer system
 
Computer generation and classification
Computer generation and classificationComputer generation and classification
Computer generation and classification
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
 
6 cpu scheduling
6 cpu scheduling6 cpu scheduling
6 cpu scheduling
 
4 threads
4 threads4 threads
4 threads
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 

5 process synchronization

  • 1. Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Chapter 5: Process Synchronization
  • 2. 5.2 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Chapter 5: Process Synchronization  Background  The Critical-Section Problem  Peterson’s Solution  Synchronization Hardware  Mutex Locks  Semaphores  Classic Problems of Synchronization  Monitors  Synchronization Examples  Alternative Approaches
  • 3. 5.3 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Objectives  To present the concept of process synchronization.  To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data  To present both software and hardware solutions of the critical-section problem  To examine several classical process-synchronization problems  To explore several tools that are used to solve process synchronization problems
  • 4. 5.4 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Background  Processes can execute concurrently  May be interrupted at any time, partially completing execution  Concurrent access to shared data may result in data inconsistency  Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes  Illustration of the problem: Suppose that we wanted to provide a solution to the consumer-producer problem that fills all the buffers. We can do so by having an integer counter that keeps track of the number of full buffers. Initially, counter is set to 0. It is incremented by the producer after it produces a new buffer and is decremented by the consumer after it consumes a buffer.
  • 5. 5.5 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Critical Section Problem  The critical section is a code segment where the shared variables can be accessed. An atomic action is required in a critical section i.e. only one process can execute in its critical section at a time.  Consider system of n processes {p0, p1, … pn-1}  Each process has critical section segment of code  Process may be changing common variables, updating table, writing file, etc  When one process in critical section, no other may be in its critical section  Critical section problem is to design protocol to solve this  Each process must ask permission to enter critical section in entry section, may follow critical section with exit section, then remainder section
  • 6. 5.6 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Critical Section  General structure of process Pi
  • 7. 5.7 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Solution to Critical-Section Problem 1. Mutual Exclusion - If process Pi is executing in its critical section, then no other processes can be executing in their critical sections 2. Progress - If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely 3. Bounded Waiting - A bound must exist on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter its critical section and before that request is granted  Assume that each process executes at a nonzero speed  No assumption concerning relative speed of the n processes
  • 8. 5.8 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Critical-Section Handling in OS Two approaches depending on if kernel is preemptive or non- preemptive  Preemptive – allows preemption of process when running in kernel mode  Non-preemptive – runs until exits kernel mode, blocks, or voluntarily yields CPU Essentially free of race conditions in kernel mode
  • 9. 5.9 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Synchronization Hardware  Many systems provide hardware support for implementing the critical section code.  All solutions below based on idea of locking  Protecting critical regions via locks  Uniprocessors – could disable interrupts  Currently running code would execute without preemption  Generally too inefficient on multiprocessor systems  Operating systems using this not broadly scalable  Modern machines provide special atomic hardware instructions  Atomic = non-interruptible
  • 10. 5.10 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Solution to Critical-section Problem Using Locks do { acquire lock critical section release lock remainder section } while (TRUE);
  • 11. 5.11 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Mutex Locks  Previous solutions are complicated and generally inaccessible to application programmers  OS designers build software tools to solve critical section problem  Simplest is mutex lock  Protect a critical section by first acquire() a lock then release() the lock  Boolean variable indicating if lock is available or not  Calls to acquire() and release() must be atomic  Usually implemented via hardware atomic instructions  But this solution requires busy waiting  This lock therefore called a spinlock
  • 12. 5.12 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Semaphore  Semaphores are integer variables that are used to solve the critical section problem by using two atomic operations, wait and signal that are used for process synchronization.  The definitions of wait and signal are as follows −  Wait The wait operation decrements the value of its argument S, if it is positive. If S is negative or zero, then no operation is performed.  wait(S)  {  while (S<=0);  S--;  }  Signal The signal operation increments the value of its argument S.  signal(S)  {  S++;  }
  • 13. 5.13 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Types of Semaphores  There are two main types of semaphores i.e. counting semaphores and binary semaphores. Details about these are given as follows −  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.  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.
  • 14. 5.14 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Semaphore Implementation  Must guarantee that no two processes can execute the wait() and signal() on the same semaphore at the same time  Thus, the implementation becomes the critical section problem where the wait and signal code are placed in the critical section  Could now have busy waiting in critical section implementation  But implementation code is short  Little busy waiting if critical section rarely occupied  Note that applications may spend lots of time in critical sections and therefore this is not a good solution
  • 15. 5.15 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Deadlock and Starvation  Deadlock – two or more processes are waiting indefinitely for an event that can be caused by only one of the waiting processes  Let S and Q be two semaphores initialized to 1 P0 P1 wait(S); wait(Q); wait(Q); wait(S); ... ... signal(S); signal(Q); signal(Q); signal(S);  Starvation – indefinite blocking  A process may never be removed from the semaphore queue in which it is suspended  Priority Inversion – Scheduling problem when lower-priority process holds a lock needed by higher-priority process  Solved via priority-inheritance protocol
  • 16. 5.16 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Classical Problems of Synchronization  Semaphore can be used in other synchronization problems besides Mutual Exclusion.  Below are some of the classical problem depicting flaws of process synchronaization in systems where cooperating processes are present.  We will discuss the following three problems:  Bounded Buffer (Producer-Consumer) Problem  Dining Philosophers Problem  The Readers Writers Problem
  • 17. 5.17 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Bounded-Buffer Problem  This problem is generalised in terms of the Producer Consumer problem, where a finite buffer pool is used to exchange messages between producer and consumer processes.  Because the buffer pool has a maximum size, this problem is often called the Bounded buffer problem.  Solution to this problem is, creating two counting semaphores "full" and "empty" to keep track of the current number of full and empty buffers respectively.
  • 18. 5.18 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition Dining Philosophers Problem  The dining philosopher's problem involves the allocation of limited resources to a group of processes in a deadlock-free and starvation-free manner.
  • 19. 5.19 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition The Readers Writers Problem  In this problem there are some processes(called readers) that only read the shared data, and never change it, and there are other processes(called writers) who may change the data in addition to reading, or instead of reading it.
  • 20. Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9th Edition End of Chapter 5