6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
5.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 5: CPU Scheduling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 13: October 12, 2010 Instructor: Bhuvan Urgaonkar.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
COSC 3407: Operating Systems Lecture 8: Semaphores, Monitors and Condition Variables.
Synchronization Principles Gordon College Stephen Brinton.
Classical Problems of Concurrency
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chapter 6: Process Synchronization. Outline Background Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores Classic Problems.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Objectives Understand.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
Process Synchronization
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Adopted from and based on Textbook: Operating System Concepts – 8th Edition, by Silberschatz, Galvin and Gagne Updated and Modified by Dr. Abdullah Basuhail,
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 23 Classic Synchronization.
CS 346 – Sect Process synchronization –What is the problem? –Criteria for solution –Producer / consumer example –General problems difficult because.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization.
6.3 Peterson’s Solution The two processes share two variables: Int turn; Boolean flag[2] The variable turn indicates whose turn it is to enter the critical.
Critical Problem Revisit. Critical Sections Mutual exclusion Only one process can be in the critical section at a time Without mutual exclusion, results.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Chap 6 Synchronization. Background Concurrent access to shared data may result in data inconsistency Maintaining data consistency requires mechanisms.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Synchronization Background The Critical-Section.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Process Synchronization
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Module 6: Process Synchronization Background The.
Chapter 6: Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 11: Synchronization (Chapter 6, cont)
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
CS 241 Section Week #7 (10/22/09). Topics This Section  Midterm Statistics  MP5 Forward  Classical Synchronization Problems  Problems.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 22 Semaphores Classic.
Producer-Consumer Problem David Monismith cs550 Operating Systems.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 5: Process Synchronization.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Synchronization Background The Critical-Section Problem Peterson’s.
6.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 6.5 Semaphore Less complicated than the hardware-based solutions Semaphore S – integer.
Deadlock and Starvation
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Process Synchronization: Semaphores
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Background on the need for Synchronization
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization – Part II
Chapter 5: Process Synchronization
Deadlock and Starvation
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization (Con’t)
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Chapter 7: Synchronization Examples
Presentation transcript:

6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Module 6: Process Synchronization

6.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Semaphore Implementation with no Busy waiting Processes block themselves instead of busy waiting Unblocked when some other process releases semaphore Maintain a waiting queue for each semaphore value (of type integer) pointer to next record in the list Two operations: block – place the process invoking the operation on the appropriate waiting queue. wakeup – remove one of processes in the waiting queue and place it in the ready queue.

6.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Semaphore Implementation with no Busy waiting (Cont.) Implementation of acquire(): Implementation of release():

6.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Semaphore Implementation with no Busy waiting (Contd.) Semaphore value can be negative Can use any order for waking up blocked processes Some might cause unbounded wait Important to ensure atomicity of acquire() and release() Disable interrupts during acquire() and release() Works for single processor environments Use software solutions to the critical sections problem

6.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Deadlocks Deadlock -- Two or more processes are waiting indefinitely for an event that can be triggered by only one of the waiting processes Let S and Q be two semaphores initialized to 1 Solutions to be discussed in next chapter Starvation – Process waiting indefinitely within a semaphore

6.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Priority Inversion Semaphores can mess up process priorities A lower priority process may hold a semaphore that a higher priority process needs A more complex scenario Low, medium and high priority processes Low priority process holds a semaphore, high priority process needs to acquire Low priority process is pre-empted by medium priority process that does not need the semaphore Priority-Inheritance protocol A process holding a semaphore will inherit the highest priority that is waiting on the resource

6.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Classical Problems of Synchronization Bounded-Buffer Problem Readers and Writers Problem Dining-Philosophers Problem

6.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-Buffer Problem Buffer with ‘N’ slots Each slot holds one item Producers continuously generate items and want to insert into the buffer Must wait if buffer has no empty slots Consumers continuously remove items from the buffer Must wait if buffer has no items Only one producer/consumer should be accessing the buffer at any given time

6.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-Buffer Solution Outline Semaphore mutex initialized to the value 1 mutex is for synchronization (prevent simultaneous access to shared buffer) Semaphore full initialized to the value 0 full indicates how many items are there in the buffer Semaphore empty initialized to the value N empty indicates number of empty slots in buffer

6.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-buffer producer

6.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-buffer consumer

6.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-buffer factory

6.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-Buffer

6.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-Buffer insert()

6.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Bounded-buffer remove()

6.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Readers-Writers Problem A data set is shared among a number of concurrent processes Readers – only read the data set; they do not perform any updates Writers – can both read and write Problem Allow multiple readers to read at the same time Only single writer can access the shared data at the same time No simultaneous reads and writes allowed

6.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Readers-Writers Solution readerCount – Integer indicating how many readers are currently reading the shared data Manipulated only by readers Initialized to zero Semaphore mutex initialized to 1 Synchronizing access to the readerCount variable (ensuring only one reader is manipulating readerCount) Semaphore db initialized to 1 Synchronizing access to the data item Ensuring only one writer is in the critical region or any number of readers

6.18 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Readers-Writers Problem Interface for read-write locks

6.19 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Writer Structure

6.20 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Reader Structure

6.21 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Shared DB

6.22 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition ReadLock Methods

6.23 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition WriteLock Methods

6.24 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Dining Philosophers Problem 5 philosopher seated on a round table Each philosopher is in a loop of alternate thinking and eating 5 chopsticks Each philosopher has one on each side Philosopher can eat when she has two chopsticks Picks up one chopstick after another Puts them back one after another Array of semaphores (1 for each chopstick)

6.25 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Dining-Philosophers Problem Semaphore chopStick [5] initialized to 1

6.26 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Philosopher Structure

6.27 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Deadlocks What if all philosophers acquire their right (or left) chopstick Nobody can progress – Deadlock !!! Solutions: Allow philosopher to pick up chopsticks if both are available (i.e., guard the array of semaphores in a critical section) Asymmetric solution – Odd philosophers acquire left chopstick first whereas even philosophers acquire right chopstick first

6.28 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Problems with Semaphores Correct use of semaphore operations: Correct  mutex.acquire() …. mutex.release() Incorrect  mutex.acquire () or mutex.release() (or both) Omitting either mutex.acquire() or mutex.release()

6.29 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Monitors Refer to the handout given in class. If you do not have the handout, please see the instructor.

6.30 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition End of Chapter 6