Process Synchronization

Slides:



Advertisements
Similar presentations
Module 6: Process Synchronization
Advertisements

Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: 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.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Process Synchronization CS 502 Spring 99 WPI MetroWest/Southboro Campus.
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.
02/23/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
02/17/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Process Synchronization Topics: 1.Background 2.The critical-section problem 3.Semaphores 4.Critical Regions 5.Monitors Topics: 1.Background 2.The critical-section.
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.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
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.
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.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 14: October 14, 2010 Instructor: Bhuvan Urgaonkar.
Silberschatz and Galvin  Operating System Concepts Module 6: Process Synchronization Background The Critical-Section Problem Synchronization.
Principles of Operating Systems Lecture 6 and 7 - Process Synchronization.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
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.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 7 Process Synchronization Slide 1 Chapter 7 Process Synchronization.
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, Lecture 11: Synchronization (Chapter 6, cont)
Operating Systems CSE 411 CPU Management Dec Lecture Instructor: Bhuvan Urgaonkar.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
Process Synchronization CS 360. Slide 2 CS 360, WSU Vancouver Process Synchronization Background The Critical-Section Problem Synchronization Hardware.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
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.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
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.
Semaphores Synchronization tool (provided by the OS) that does not require busy waiting. Logically, a semaphore S is an integer variable that, apart from.
Chapter 6: Process Synchronization
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Process Synchronization
Chapter 5: Process Synchronization
Process Synchronization: Semaphores
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Background on the need for Synchronization
Process Synchronization
Chapter 5: Process Synchronization – Part II
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Chapter 6: Process Synchronization
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization (Con’t)
Lecture 25 Syed Mansoor Sarwar
Topic 6 (Textbook - Chapter 5) Process Synchronization
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Module 7a: Classic Synchronization
Lecture 2 Part 2 Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
Presentation transcript:

Process Synchronization Background The Critical-Section Problem Semaphores A Classical Problem of Synchronization The Dining-Philosophers Problem Operating System Concepts

Operating System Concepts Background Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the orderly execution of cooperating processes. Operating System Concepts

The Critical-Section Problem n processes all competing to use some shared data. Each process has a code segment, called critical section, in which the shared data is accessed. Problem – ensure that when one process is executing in its critical section, no other process is allowed to execute in its critical section. Structure of process Pi repeat entry section critical section exit section reminder section until false; Operating System Concepts

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. Operating System Concepts

Operating System Concepts Semaphores Semaphore is a synchronization tool which can be used to deal with the critical-section problem. A semaphore is a protected variable whose value can be accessed and altered only by the operations P (wait) and V (signal) and an initialization operation we shall call semaphore-initialize. Operating System Concepts

Operating System Concepts Semaphores (Cont.) The classical definitions of wait and signal are: The P operation (wait) on semaphore S, written P(S), operates as follows: if S > 0 then S := S – 1; else (wait on S) The V operation (signal) on semaphore S, written V(S), operates as follows: if (one or more processes are waiting on S) then (let one of these processes proceed) else S:= S + 1 Operating System Concepts

Two Types of Semaphores Counting semaphore – integer value can range over an unrestricted domain. Binary semaphore – integer value can range only between 0 and 1; can be simpler to implement. Can implement a counting semaphore S as a binary semaphore. Starvation – indefinite blocking. A process may never be removed from the semaphore queue in which it is suspended. The implementation of P and V guarantees that processes will not suffer indefinite postponement. Operating System Concepts

Example: Critical Section of n Processes The n processes share a semaphore initialized to 1. Shared variables var mutex : semaphore initially mutex = 1 /* mutual exclusion Each process Pi is organized as follows: repeat wait(mutex); critical section signal(mutex); remainder section until false; This is a Mutual-Exclusion implementation with semaphores. Operating System Concepts

Semaphore as General Synchronization Tool Consider two concurrently running processes: P1 with a statement S1 and P2 with a statement S2. Suppose that we require that S2 be executed only after S1 has completed. This can be done by letting P1 and P2 share a common semaphore synch, initialized to 0, and by inserting the statements in process P1: S1; signal (synch); and the statements in process P2: wait (synch); S2; Because synch is initialized to 0, P2 will execute S2 only after P1 has invoked signal (synch), which is after S1. Operating System Concepts

Example: 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 step1: wait(S); wait(Q); step2: wait(Q); wait(S);   step3: signal(S); signal(Q); step4: signal(Q) signal(S); Operating System Concepts

Example: Deadlock and Starvation (Cont.) Step 1: Suppose that P0 executes wait(S) and then P1 executes wait(Q). Step 2: When P0 executes wait(Q), it must wait until P1 executes signal(Q). Step 2: Also, when P1 executes wait(S), it must wait until P0 executes signal(S). Step 3 & 4: Since these signal operations cannot be executed, P0 and P1 are deadlocked. A set of processes is in a deadlock state when every process in the set is waiting for an event that can be caused only by another process in the set. Operating System Concepts

A Classical Problem of Synchronization Dining-Philosophers Problem: Rice Operating System Concepts

Dining-Philosophers Problem Table, a bowl of rice in center, five chairs, and five chopsticks, also in each chair there is a philosopher. A philosopher may pick up only one chopstick at a time. When a hungry philosopher has both her chopsticks at the same time, she eats without releasing her chopsticks. When she is finished eating, she puts down both of her chopsticks and starts thinking. From time to time, a philosopher gets hungry and tries to pick up the two chopsticks that are closest to her (chopsticks between her left and right neighbors). Operating System Concepts

Dining-Philosophers Problem (Cont.) Solution: Present each chopstick by a semaphore. A philosopher tries to grab the chopstick by executing a wait operation on that semaphore. She releases her chopsticks by executing the signal operation on the appropriate semaphores. This solution guarantees that no two neighbors are eating simultaneously, but it could cause a deadlock. Suppose all five philosophers become hungry simultaneously, and each grabs her left chopstick. When each philosopher tries to grab her right chopstick, she will cause the possibility that the philosophers will starve to death. Operating System Concepts

Dining-Philosophers Problem (Cont.) We present a solution to the dining-philosophers problem that ensure freedom from deadlock. Allow at most 4 philosophers to be sitting simultaneously at the table. Allow a philosopher to pick up her chopstick only if both chopsticks are available. An odd philosopher picks up first her left chopstick and then her right chopstick, whereas, an even philosopher picks up her right chopstick first and then her left chopstick. Note: A deadlock-free solution does not necessarily eliminate the possibility of starvation. Operating System Concepts