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.

Slides:



Advertisements
Similar presentations
Operating Systems Semaphores II
Advertisements

Operating Systems: Monitors 1 Monitors (C.A.R. Hoare) higher level construct than semaphores a package of grouped procedures, variables and data i.e. object.
– R 7 :: 1 – 0024 Spring 2010 Parallel Programming 0024 Recitation Week 7 Spring Semester 2010.
Ch 7 B.
Ch. 7 Process Synchronization (1/2) I Background F Producer - Consumer process :  Compiler, Assembler, Loader, · · · · · · F Bounded buffer.
Chapter 6 Process Synchronization Bernard Chen Spring 2007.
Chapter 6: Process Synchronization
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 6: Process Synchronization.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Synchronization Principles Gordon College Stephen Brinton.
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.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
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.
What we will cover… Process Synchronization Basic Concepts
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.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
CS444/CS544 Operating Systems Classic Synchronization Problems 2/26/2007 Prof. Searleman
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.
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.
More Synchronisation Last time: bounded buffer, readers-writers, dining philosophers Today: sleeping barber, monitors.
Monitors: An Operating System Structuring Concept
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.
1 Process Synchronization – Outline Why do processes need synchronization ? What is the critical-section problem ? Describe solutions to the critical-section.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
1 Chapter 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Special Machine Instructions for Synchronization Semaphores.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
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 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  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
1 Condition Variables CS 241 Prof. Brighten Godfrey March 16, 2012 University of Illinois.
13/03/07Week 21 CENG334 Introduction to Operating Systems Erol Sahin Dept of Computer Eng. Middle East Technical University Ankara, TURKEY URL:
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
CSC 360 Instructor: Kui Wu More on Process Synchronization Semaphore, Monitor, Condition Variables.
Chapter 71 Monitors (7.7)  A high-level-language object-oriented concept that attempts to simplify the programming of synchronization problems  A synchronization.
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.
Chapter 6 Synchronization Dr. Yingwu Zhu. The Problem with Concurrent Execution Concurrent processes (& threads) often access shared data and resources.
Deadlock and Starvation
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Classical Synchronization Problems
Deadlock and Starvation
Chapter 5: Process Synchronization
An object-based synchronization mechanism.
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Module 7a: Classic 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
Chapter 6 Synchronization Principles
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
Chapter 6: Synchronization Tools
Presentation transcript:

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 added new slides

Problems with Semaphores  Correct use of semaphore operations may not be easy, since they may be scattered throughout a program:

Monitors  A high-level abstraction that provides equivalent functionality to that of semaphores and that is easier to control  The monitor construct has been implemented in a number of programming languages and as a program library  A programmer does not need to manually write the entire synchronization code

Monitors monitor monitor-name { // shared variables declarations procedure P1 (…) { …. } … procedure Pn (…) {……} Initialization code (….) { … } … }

Monitor  Protect shared objects within an abstraction  Provide encapsulation  Accesses to a shared object is confined within a monitor  Provide mutual exclusive accesses  No two process can be active at the same time within a monitor monitor Monitor already provides lock box and corresponding control mechanism

Shared Device Program with Monitor  N devices in the system  Use any of them as long as it is free monitor mutex_devices: free: array [0..N–1] of boolean; -- initialized to true int acquire () { for i := 0 to N–1 do if (free[i]) then { free[i] := false; return (i); } else return (–1); } void release (index: integer) { free[index] := true; }

Synchronization within a Hoare-style Monitor  Monitor guarantees mutual exclusive accesses  May still need synchronization  E.g., shared device problem  wait for device to become available  E.g., bounded buffer problem  wait for buffer to become full/empty  Monitor guarantees mutual exclusive accesses  May still need synchronization  Monitor also provides condition variables  To achieve conditional wait and support synchronization  Associated with each condition variable  A condition queue  The wait and signal functions  If wait inside a monitor  Same as wait inside a lockbox protected by a semaphore (mutex)  Has potential of deadlock  Monitor provides mechanism to counter it

Synchronization within a Hoare-style Monitor monitor condition queue x condition variable y

Bounded Buffer Problem with a Hoare- style Monitor monitor bounded_buffer buffer: array [0..n-1] of item; in, out, counter: integer := 0; empty, full: condition; function deposit (item) function remove (&item) { if (counter = n) then { if (counter = 0) then full.wait; empty.wait; buffer[in] := item; item := buffer[out]; in := (in+1) % n; out := (out+1) % n; counter := counter + 1; counter := counter – 1; empty.signal; full.signal; } }

Bounded Buffer Problem with a Hoare- style Monitor Producer process: repeat produce item deposit (item); until false; Consumer process: repeat remove (item); consume item; until false;

Bounded Buffer Problem with a Hoare- style Monitor (Signal-and-Wait Discipline) monitor condition queue full empty function deposit (item) { if (counter = n) then full.wait; buffer[in] := item; in := (in+1) % n; counter := counter + 1; empty.signal; } function remove (&item) { if (counter = 0) then empty.wait; item := buffer[out]; out := (out+1) % n; counter := counter – 1; full.signal; }

Bounded Buffer Problem with a Hoare- style Monitor (Signal-and-Wait Discipline) monitor condition queue full empty function fun1 () { … empty.signal; …} function fun2 () { … empty.wait; …} A process signals and then must be blocked; signal-and-wait Process scheduling associated with a signal must be perfectly reliable

Bounded Buffer Problem with a Hoare- style Monitor (Signal-and-Wait Discipline) monitor condition queue full empty function deposit (item) { if (counter = n) then full.wait; buffer[in] := item; in := (in+1) % n; counter := counter + 1; empty.signal; } function remove (&item) { if (counter = 0) then empty.wait; item := buffer[out]; out := (out+1) % n; counter := counter – 1; full.signal; }

Bounded Buffer Problem with a Mesa Monitor (Signal-and-Continue Discipline) monitor bounded_buffer buffer: array [0..n-1] of item; in, out, counter: integer := 0; empty, full: condition; function deposit (item) function remove (&item) { while (counter = n) then { while (counter = 0) then full.wait; empty.wait; buffer[in] := item; item := buffer[out]; in := (in+1) % n; out := (out+1) % n; counter := counter + 1; counter := counter – 1; empty.notify; full. notify; } }

Bounded Buffer Problem with a Mesa Monitor (Signal-and-Continue Discipline) monitor condition queue full empty  watchdog timer function deposit (item) { while (counter = n) then full.wait; buffer[in] := item; in := (in+1) % n; counter := counter + 1; empty.notify; } function remove (&item) { while (counter = 0) then empty.wait; item := buffer[out]; out := (out+1) % n; counter := counter – 1; full.notify; }

Monitor  Monitor provides encapsulation  Accesses to a shared object is confined within a monitor  Easier to debug the code  E.g., bounded buffer problem, deposit & remove functions  What should be encapsulated?  Too much  reduce concurrency  Some part of the code that can be executed concurrently, if encapsulated in the monitor, can cause reduced concurrency