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.

Slides:



Advertisements
Similar presentations
Synchronization and Deadlocks
Advertisements

Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Ch 7 B.
CSCC69: Operating Systems
Chapter 6: 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.
CH7 discussion-review Mahmoud Alhabbash. Q1 What is a Race Condition? How could we prevent that? – Race condition is the situation where several processes.
Concurrency: Mutual Exclusion and Synchronization Why we need Mutual Exclusion? Classical examples: Bank Transactions:Read Account (A); Compute A = A +
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Concurrent & Distributed Systems Lecture 3: Processes interacting by sharing resources Asynchronous processes can interact by sharing a common resource.
Concurrent & Distributed Systems Lecture 5: Semaphores and Synchronisation Concurrent processes which don’t interact in some way don’t form an interesting.
5.6 Semaphores Semaphores –Software construct that can be used to enforce mutual exclusion –Contains a protected variable Can be accessed only via wait.
Concurrent & Distributed Systems Lecture 4: ME solutions Lecture 3 considered possible algorithms for achieving Mutual Exclusion between the critical sections.
6/16/2015 Chapter Eight Process Synchronisation. Index Objectives Concurrent processes and Asynchronous concurrent processes Process synchronisation Mutual.
Synchronization: Monitors Hank Levy. 6/21/20152 Synchronization with Semaphores Semaphores can be used to solve any of the traditional synchronization.
1 ) Data Attributes 2) Declarations, Assignment and Instantiation 3) Global and Local Data 4) Variables 5) Constants 6) Example programs COMP205 IMPERATIVE.
Monitors CSCI 444/544 Operating Systems Fall 2008.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
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.
Data Abstraction and Object- Oriented Programming CS351 – Programming Paradigms.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Operating Systems CMPSCI 377 Lecture.
University of Pennsylvania 9/28/00CSE 3801 Concurrent Programming (Critical Regions, Monitors, and Threads) CSE 380 Lecture Note 6 Insup Lee.
02/19/2007CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Operating Systems CSE 411 CPU Management Oct Lecture 13 Instructor: Bhuvan Urgaonkar.
Monitor  Giving credit where it is due:  The lecture notes are borrowed from Dr. I-Ling Yen at University of Texas at Dallas  I have modified them and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 8: More About OOP and GUIs.
Experience with Processes and Monitors in Mesa
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Introduction to Concurrency.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
11/21/20151 Operating Systems Design (CS 423) Elsa L Gunter 2112 SC, UIUC Based on slides by Roy Campbell, Sam.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Chapter 6 – Process Synchronisation (Pgs 225 – 267)
Introduction to Classes and Objects. Real Life When a design engineer needs an electrical motor he doesn’t need to worry about –How a foundry will cast.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Problems with Semaphores Used for 2 independent purposes –Mutual exclusion –Condition synchronization Hard to get right –Small mistake easily leads to.
13-1 Chapter 13 Concurrency Topics Introduction Introduction to Subprogram-Level Concurrency Semaphores Monitors Message Passing Java Threads C# Threads.
CS533 – Spring Jeanie M. Schwenk Experiences and Processes and Monitors with Mesa What is Mesa? “Mesa is a strongly typed, block structured programming.
U NIVERSITY OF M ASSACHUSETTS A MHERST Department of Computer Science Computer Systems Principles Synchronization Emery Berger and Mark Corner University.
Operating System Concepts and Techniques Lecture 13 Interprocess communication-2 M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To design and implement programs with more than one function ❏ To be able to.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
CS162 Section 2. True/False A thread needs to own a semaphore, meaning the thread has called semaphore.P(), before it can call semaphore.V() False: Any.
CS703 - Advanced Operating Systems
Concepts of Object Oriented Programming
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
“Language Mechanism for Synchronization”
Process Synchronization
Concurrent Processes.
Functions Review.
CS 326 Programming Languages, Concepts and Implementation
Chapter 5: Process Synchronization
CS510 Operating System Foundations
Chapter 4 Functions Objectives
Midterm review: closed book multiple choice chapters 1 to 9
Semaphore Originally called P() and V() wait (S) { while S <= 0
Lecture 2 Part 2 Process Synchronization
Concurrency: Mutual Exclusion and Process Synchronization
CSE 451: Operating Systems Autumn Lecture 8 Semaphores and Monitors
Monitor Giving credit where it is due:
CSE 451: Operating Systems Autumn Lecture 7 Semaphores and Monitors
Tonga Institute of Higher Education IT 141: Information Systems
Synchronization: Monitors
CSE 153 Design of Operating Systems Winter 19
Tonga Institute of Higher Education IT 141: Information Systems
Chapter 6: Synchronization Tools
Presentation transcript:

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 (usually stored on an EPROM) which came on single board computers when micro-processing first started out in the 1980’s. An example was SWTBUG used in Motorola’s rival to the first Intel Systems. Bill Gates started out here too. These days we would call such a thing a ‘kernal’. –The Monitors we are dealing with are modern tools for concurrency. –They were the pre-cursors of Object Oriented Programming (now an essential Software Engineering tool Why? –To carry the encapsulation principle (Critical Regions have this for data only) as far as possible, to achieve all the quality benefits that encapsulation brings.

Concurrent & Distributed Systems Lecture 10: Monitors: How? How do Monitors work –First of all a general picture: –Notes: In a Pascal style annotation, Syntax might look like: Monitor x Data declarations procedure1 procedure2 … Initialisation End x Basis of concurrency control in MODULA 2 Also in ADA, MESA, Turing Plus Origins C.Hoare (Oxford) B. Hansen (Harvard, USA) Local data Procedures Initialisation code Only for Monitor’s own local data Monitor needs to be set up in a known state Totally protected from things going on in the rest of the software system To implement the functions provided by the Monitor

Concurrent & Distributed Systems Lecture 10: Monitors: What? –Compared with OOP, Monitors lack inheritance and the idea of classes. Tis is because of its origins as a concurrent quality and safety tool. Both the things above are to do with software productivity, which is a more modern concern. –Monitor operation, the rules: Monitors themselves have global scope. Concurrent application processes can call the procedures of the Monitor to access the Monitor’s data. Monitor data cannot be accessed in any other way – ie there is very strong encapsulation. Only one Monitor procedure at a time can access the data (the compiler for the Monitors language has to ensure this somehow – but that is the compiler writers problem – applications programmers see the Monitor simply as a tool which obeys the rules. –This ensures mutually exclusive access to the data –So Monitors will have have potential queues of processes which might be trying to access the data (via one of the Monitor procedures, of course) when this is not possible

Concurrent & Distributed Systems Lecture 10: Monitors: an example –Example: How to use Monitors to achieve mutual exclusion. The basic idea is simple – turn all the critical sections in the different processes into procedures inside the monitor – then they will automatically be mutually exclusive. –So would be implemented by a monitor and simply used as below: Process P wait(s) operations x, y, z Signal(s) ---- Process P wait(s) operations p, q, r Signal(s) ---- Local data Proc A x, y, z code Procedures Initialisation code Proc B p, q, r code ME1 Process P ME1.A ---- Process P ME1.B ----

Concurrent & Distributed Systems Lecture 10: Monitors: Condition Variables 1 –As for critical regions, encapsulation leads to the need for conditional entry to the monitor. This is done by –Condition Variables There are two possible operations on a Condition Variable There are two different syntaxes for these. Most common syntax is cwait(x) and csignal(x), where x is the Condition Variable Note – these are not the same as the wait and signal operations on a semaphore!! x is not a semaphore. x is not even a variable (despite being called a Condition Variable). x is just a ‘tag’ or a ‘label’, whose only purpose is to allow us to link the right cwait to the right csignal, when there are lots of them. Another syntax is delay(x) or suspend(x) and resume(x)

Concurrent & Distributed Systems Lecture 10: Monitors: Condition Variables 2 –How do Condition Variables work? –cwait(x) puts the calling procedure (one of the procedures in the monitor) to sleep. This removes mutually access to the monitor and so allows other monitor procedures to start work. –This continues until another monitor procedure executes a csignal(x), when mutual exclusion is re-established. Note – you can now see why we need the tag ‘x’ to make sure that the csignal refers to the correct cwait. –If a csignal(x) is executed and there is no procedure asleep on a corresponding cwait(x), then it is just ignored.

Concurrent & Distributed Systems Lecture 10: Monitors: Condition Variables 3 –Problem! Q says cwait(x) then later, P says csignal(x) –After the csignal, we must have mutual exclusion, so which procedure continues P or Q? This is a question of Monitor design – it has to be one way or the other, P or Q, and leads to two different versions of monitors. Charles Hoare’s version says Q continues so P waits until Q leaves the monitor, or until Q sleeps again. - easier to implement - most common B. Hansen’s version says P continues. - Q will now resume later and the condition may be out of date! Local data Proc Q cwait(x) Procedures Initialisation code Proc P ---- csignal(x) ----