Concurrent & Distributed Systems Lecture 3: Processes interacting by sharing resources Asynchronous processes can interact by sharing a common resource.

Slides:



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

CIS 540 Principles of Embedded Computation Spring Instructor: Rajeev Alur
Synchronization and Deadlocks
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
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
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.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
Efficiency of Algorithms
Chapter 3 The Critical Section Problem
Parallel Processing (CS526) Spring 2012(Week 6).  A parallel algorithm is a group of partitioned tasks that work with each other to solve a large problem.
Concurrent & Distributed Systems Lecture 2: Introduction to interacting processes Recap –Concurrent processes could be pseudo-parallel Sharing a single.
CY2003 Computer Systems Lecture 05 Semaphores - Theory.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
Concurrency.
Threading Part 2 CS221 – 4/22/09. Where We Left Off Simple Threads Program: – Start a worker thread from the Main thread – Worker thread prints messages.
Race Conditions Critical Sections Deker’s Algorithm.
Efficiency of Algorithms
Concurrent & Distributed Systems Lecture 5: Semaphores and Synchronisation Concurrent processes which don’t interact in some way don’t form an interesting.
Concurrent & Distributed Systems Lecture 4: ME solutions Lecture 3 considered possible algorithms for achieving Mutual Exclusion between the critical sections.
Concurrent Processes Lecture 5. Introduction Modern operating systems can handle more than one process at a time System scheduler manages processes and.
Synchronization Principles. Race Conditions Race Conditions: An Example spooler directory out in 4 7 somefile.txt list.c scores.txt Process.
University of Pennsylvania 9/19/00CSE 3801 Concurrent Processes CSE 380 Lecture Note 4 Insup Lee.
Concurrent & Distributed Systems Lecture 10: Monitors What? –First of all, what NOT! The term ’monitor’ was used in the past for the mini operating system.
Chapter 2.3 : Interprocess Communication
CS444/CS544 Operating Systems Synchronization 2/14/2007 Prof. Searleman
Computer Science Lecture 12, page 1 CS677: Distributed OS Last Class Vector timestamps Global state –Distributed Snapshot Election algorithms.
CS Introduction to Operating Systems
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Concurrency Recitation – 2/24 Nisarg Raval Slides by Prof. Landon Cox.
1 Thread Synchronization: Too Much Milk. 2 Implementing Critical Sections in Software Hard The following example will demonstrate the difficulty of providing.
Nachos Phase 1 Code -Hints and Comments
The Critical Section Problem
Operating Systems Lecture 2 Processes and Threads Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing Liu School of.
28/10/1999POS-A1 The Synchronization Problem Synchronization problems occur because –multiple processes or threads want to share data; –the executions.
Games Development 2 Concurrent Programming CO3301 Week 9.
COMP 111 Threads and concurrency Sept 28, Tufts University Computer Science2 Who is this guy? I am not Prof. Couch Obvious? Sam Guyer New assistant.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Mutual Exclusion.
11/18/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 5: Process Synchronization.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
CY2003 Computer Systems Lecture 04 Interprocess Communication.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Week 8 - Wednesday.  What did we talk about last time?  Level order traversal  BST delete  2-3 trees.
CS399 New Beginnings Jonathan Walpole. 2 Concurrent Programming & Synchronization Primitives.
Monitors and Blocking Synchronization Dalia Cohn Alperovich Based on “The Art of Multiprocessor Programming” by Herlihy & Shavit, chapter 8.
C H A P T E R E L E V E N Concurrent Programming Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CS333 Intro to Operating Systems Jonathan Walpole.
Mutual Exclusion Algorithms. Topics r Defining mutual exclusion r A centralized approach r A distributed approach r An approach assuming an organization.
Implementing Mutual Exclusion Andy Wang Operating Systems COP 4610 / CGS 5765.
Mutual Exclusion -- Addendum. Mutual Exclusion in Critical Sections.
Background on the need for Synchronization
G.Anuradha Reference: William Stallings
Chapter 26 Concurrency and Thread
Background and Motivation
Implementing Mutual Exclusion
Implementing Mutual Exclusion
CSE 451: Operating Systems Autumn 2003 Lecture 7 Synchronization
CSE 451: Operating Systems Autumn 2005 Lecture 7 Synchronization
CSE 451: Operating Systems Winter 2003 Lecture 7 Synchronization
CSE 153 Design of Operating Systems Winter 19
CS333 Intro to Operating Systems
Foundations and Definitions
“The Little Book on Semaphores” Allen B. Downey
Don Porter Portions courtesy Emmett Witchel
Presentation transcript:

Concurrent & Distributed Systems Lecture 3: Processes interacting by sharing resources Asynchronous processes can interact by sharing a common resource. In some cases this can create Critical Sections in the processes. Ways of making these Mutually Exclusive have to be found. This lecture uses a simple example of how this can happen, allowing us to do some conceptual problem solving as well as some practical work. It is essentially the same problem as the Travel Agent example, but easier to work with. The lecture introduces you to the idea of abstractions The lecture introduces you to the idea of Process Annotations

Concurrent & Distributed Systems The Ornamental Gardens abstraction: 1 This is a standard abstraction representing multiple concurrent processes which share a resource in an unsafe way, unless parts of each process (the Critical Sections) are made Mutually Exclusive (ME) –It is used a lot since it is easy to model in software (CCP4 in our lab) –It is a very good ‘testbed’ for ways of providing the ME (by conventional algorithms or by other mechanisms) The idea is simple: there is a walled garden with a number of entry turnstiles (at least 2), where people can enter the garden. The turnstiles record the number of people who have entered (one global total shared by all the turnstile processes). There is one exit and at the end of the day, the warden uses the global total to check that everybody has left for the day. It would be unsafe to leave anybody in the garden because the lions wake up at night! In the lab, CCP4 shows the basic abstraction and what can go wrong, CCP5,6,7 all show various attempts to cure the problem by making the Critical Sections Mutually Exclusive

Concurrent & Distributed Systems Ornamental Gardens: 2 There can be > 2 entrance turnstiles, but only one exit Nv is a globally shared variable, among the entrance processes Turnstile 1 Turnstile 2 Exit Number of visitors (Nv) Lock gate after letting out Nv people Admit new people one by one Nv :=Nv+1 Admit new people one by one Nv :=Nv+1

Concurrent & Distributed Systems Ornamental Gardens: 3 Process Annotations Nv is set to zero at the beginning of the day When simulated on a computer, the increment of Nv is done via two local variables X and Y (this is deliberate, so that interleaving of process steps can occur and cause a safety problem) The processes involve people, and so are asynchronous –So there are many detailed scenarios as to the actual ordering of    -  Check the effect of this by running CCP4 a few times) Turnstile 1 Repeat ----  X := Nv  X := X+1  Nv := X ---- Until no more admissions Turnstile 2 Repeat ----  Y := Nv  Y := Y+1  Nv := Y ---- Until no more admissions

Concurrent & Distributed Systems ME by brute force Possibility 1: Turn off the scheduler before and after each critical section –NB This can be done in MultiA.inc by placing $U- and $U+ in the code Problems –Not many Operating Systems allow the programmer to do that! (unlike MultiA.inc, where we have control) –There could be lots of other processes not involved in this pair of Critical Sections and they will also be denied access to the CPU Turnstile 1 Repeat ---- da di da ---- $U-  X := Nv  X := X+1  Nv := X $U Until no more admissions Turnstile 2 Repeat da di da $U_  Y := Nv  Y := X+1  Nv := Y $U Until no more admissions Linked pair of Critical Sections

Concurrent & Distributed Systems Mutual Exclusion by using a Single Key (CCP5) Only allow processes access to the CS if the process has the global key –This is the old fashioned way single track railways used to work –The key can be given to either process, on initialization, eg key :=1. Good!Neither process can access its CS if the other one already is, with the key Bad –What happens if the two processes are asymmetrical in any way In duration In speed –What about more than two processes –What about busy waiting Turnstile 1 Repeat ---- While Key=2 remain busy waiting  X := Nv  X := X+1  Nv := X Key := Until no more admissions Turnstile 2 Repeat ---- While Key=1 remain busy waiting  Y := Nv  Y := X+1  Nv := Y Key := Until no more admissions Linked pair of Critical Sections

Concurrent & Distributed Systems Mutual Exclusion by using Own Keys :1 (CCP6) Give each process a flag that the other process can see, and check, before going into its Critical Section Sensibly, assume both processes don’t start in their critical sections. P1, P2 := outOfCritical Good!Asymmetry between processes doesn’t matter Bad –Unsafe scenarios exist, eg ,   – run CCP6 a few times to see this –What about busy waiting? –What about > 2 processes? Turnstile 1 Repeat ----  While (P2 = inCritical) remain busy waiting  P1 := inCritical X := Nv X := X+1 Nv := X P1 := outOfCritical ---- Until no more admissions Turnstile 2 Repeat ----  While (P1 = inCritical) remain busy waiting  P2 := inCritical Y := Nv Y := X+1 Nv := Y P2 := outOfCritical ---- Until no more admissions Linked pair of Critical Sections

Concurrent & Distributed Systems Mutual Exclusion by using Own Keys :2 (CCP6a) Avoid the unsafe interleaving scenario of CCP6 by setting the flag early, before the test Again intitialise the flags as: P1, P2 := outOfCritical Good!Asymmetry between processes still doesn’t matter, and no unsafe scenarios Bad –‘Unlive’ scenarios exist, eg ,   – run CCP6a a few times to see this –What about busy waiting? –What about > 2 processes? Is there a problem with ‘test and set’ with these flags? Turnstile 1 Repeat ----  P1 := inCritical  While (P2 = inCritical) remain busy waiting X := Nv X := X+1 Nv := X P1 := outOfCritical ---- Until no more admissions Turnstile 2 Repeat ----  P2 := inCritical  While (P1 = inCritical) remain busy waiting Y := Nv Y := X+1 Nv := Y P2 := outOfCritical ---- Until no more admissions Linked pair of Critical Sections