28/10/1999POS-A1 The Synchronization Problem Synchronization problems occur because –multiple processes or threads want to share data; –the executions.

Slides:



Advertisements
Similar presentations
Operating Systems Part III: Process Management (Process Synchronization)
Advertisements

Synchronization. How to synchronize processes? – Need to protect access to shared data to avoid problems like race conditions – Typical example: Updating.
Process Synchronization A set of concurrent/parallel processes/tasks can be disjoint or cooperating (or competing) With cooperating and competing processes.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Process Synchronization Continued 7.2 The Critical-Section Problem.
Mutual Exclusion By Shiran Mizrahi. Critical Section class Counter { private int value = 1; //counter starts at one public Counter(int c) { //constructor.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 6 (a): Synchronization.
Chapter 6: Process Synchronization
Background Concurrent access to shared data can lead to inconsistencies Maintaining data consistency among cooperating processes is critical What is wrong.
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.
Multiprocessor Synchronization Algorithms ( ) Lecturer: Danny Hendler The Mutual Exclusion problem.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
1 Operating Systems, 122 Practical Session 5, Synchronization 1.
Mutual Exclusion.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
China’s Software Industry August 2006 Instructor: Hengming Zou, Ph.D.
Chapter 3 The Critical Section Problem
CPSC 668Set 7: Mutual Exclusion with Read/Write Variables1 CPSC 668 Distributed Algorithms and Systems Fall 2009 Prof. Jennifer Welch.
The Critical-Section Problem
1 Tuesday, June 20, 2006 "The box said that I needed to have Windows 98 or better... so I installed Linux." - LinuxNewbie.org.
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.
University of Pennsylvania 9/19/00CSE 3801 Concurrent Processes CSE 380 Lecture Note 4 Insup Lee.
Concurrency in Distributed Systems: Mutual exclusion.
Chapter 6: Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Module 6: Synchronization 6.1 Background 6.2 The Critical-Section.
Synchronization (other solutions …). Announcements Assignment 2 is graded Project 1 is due today.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Process Synchronization.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
The Critical Section Problem
Process Synchronization Continued 7.2 Critical-Section Problem 7.3 Synchronization Hardware 7.4 Semaphores.
THIRD PART Algorithms for Concurrent Distributed Systems: The Mutual Exclusion problem.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
DISTRIBUTED ALGORITHMS AND SYSTEMS Spring 2014 Prof. Jennifer Welch CSCE
Mutual Exclusion Using Atomic Registers Lecturer: Netanel Dahan Instructor: Prof. Yehuda Afek B.Sc. Seminar on Distributed Computation Tel-Aviv University.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Process Synchronization Concurrent access to shared data may result in data inconsistency. Maintaining data consistency requires mechanisms to ensure the.
1 Concurrent Processes. 2 Cooperating Processes  Operating systems allow for the creation and concurrent execution of multiple processes  concurrency.
Operating Systems CMPSC 473 Mutual Exclusion Lecture 11: October 5, 2010 Instructor: Bhuvan Urgaonkar.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
Synchronization CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CS4315A. Berrached:CMS:UHD1 Process Synchronization Chapter 8.
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.
CE Operating Systems Lecture 8 Process Scheduling continued and an introduction to process synchronisation.
Synchronization Questions answered in this lecture: Why is synchronization necessary? What are race conditions, critical sections, and atomic operations?
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
Background on the need for Synchronization
Chapter 5: Process Synchronization
Chapter 5: Process Synchronization
143a discussion session week 3
CSCE 668 DISTRIBUTED ALGORITHMS AND SYSTEMS
The Critical-Section Problem
Lecture 19 Syed Mansoor Sarwar
Introduction to Cooperating Processes
Lecture 20 Syed Mansoor Sarwar
Process Synchronization
Critical section problem
Grades.
Chapter 6: Process Synchronization
Lecture 21 Syed Mansoor Sarwar
Chapter 6: Synchronization Tools
CSE 542: Operating Systems
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

28/10/1999POS-A1 The Synchronization Problem Synchronization problems occur because –multiple processes or threads want to share data; –the executions of these processes interleave in arbitrary fashions.

28/10/1999POS-A2 A Simple Example Two processes trying to increment a common variable V (suppose V = 0 initially): Process 1 : load V,R add 1,R store R,V Process 2 : load V,R add 1,R store R,V load V,R load V,R add 1,R add 1,R store R,V store R,V V load V,R add 1,R store R,V V = 1V = 2

28/10/1999POS-A3 Critical Section It can be easily seen that the “load” of one process must follow the “store” of the other process. The three instructions must be executed atomically, thus forming a critical section (CS). –Ie., when one process is in its critical section, no other process can be in its critical section at the same time.

28/10/1999POS-A4 2-Process CS Algorithms 1 & 2 do not satisfy the progress requirement. –To prove an algorithm not satisfying a requirement, we only need to find one case (ie., “there exists”). –To prove an algorithm satisfying a requirement, we have to prove that it does so for all cases (ie., “for all”).

28/10/1999POS-A5 One Failure Case of Algo. 1 while turn  0 do no-op; CS turn = 1; exit; // remainder section while turn  1 do no-op; CS turn = 0; remainder section; while turn  1 do no-op; time No more progress!

28/10/1999POS-A6 One Failure Case of Algo. 2 flag[0] = true; flag[1] = true; while flag[0] do no-op; flag[0] = true; flag[1] = true; while flag[1] do no-op; No progress either case!

28/10/1999POS-A7 Algorithm 3 – Mutual Exclusion “turn”, a shared variable, is either 0 or 1, and hence only one process can pass through the while statement at a time. –This is a direct proof.

28/10/1999POS-A8 Proving “For All” Instead of a direct proof, to prove “for all”, we could use proof by contradiction. –Assume there exists a case not satisfying a requirement; show that such a case won’t exist.

28/10/1999POS-A9 Algorithm 3 - Progress Proof by contradiction Assume there exists a time when both processes are executing the while statement and cannot get into the CS. –Then both “turn = 0” and “turn = 1” must be true – an impossible case! The assumption cannot be true.

28/10/1999POS-A10 Algorithm 3 – Bounded Waiting Suppose P 0 is executing in the CS, and P 1 is waiting (executing the while). –“flag[0]” and “turn = 0” in P 1 ’s while statement are true. –When P 0 exits the CS, it sets “flag[0]” to false. –Two possibilities at this point: either P 0 continues to execute or P 1 enters the CS. »Cont’d …

28/10/1999POS-A11 Bounded Waiting (cont’d) –Suppose P 0 continues to execute and arrives at its while statement. It will be stuck at the while statement because both “flag[1]” and “turn = 1” would be true. –Hence, in either case, P 1 is the next one to enter the CS.

28/10/1999POS-A12 The Bakery Algorithm – Solving the n-process CS The counter can serve only one customer at a time. The counter is the CS. When a customer enters the bakery, it picks a number which is 1 + the largest number being held by a existing customer. »Cont’d …

28/10/1999POS-A13 Bakery Algorithm (cont’d) To get to the counter, the customer compares its number with every one of the existing customers. –It holds a bit when coming to a customer, i, who is in the middle of getting its number (the “choosing[i]” variable is used). –If its number is smaller than all existing numbers, the customer gets the counter.