University of Pennsylvania 9/28/00CSE 3801 Concurrent Programming (Critical Regions, Monitors, and Threads) CSE 380 Lecture Note 6 Insup Lee.

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.
Synchronization with Eventcounts and Sequencers
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
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.
Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware Semaphores.
1 Semaphores and Monitors CIS450 Winter 2003 Professor Jinhua Guo.
Lab2: Semaphores and Monitors. Credits Material in this slide set is from G. Andrews, “Foundation of Multithreaded, Parallel, and Distributed Programming”,
1 Semaphores and Monitors: High-level Synchronization Constructs.
Enforcing Mutual Exclusion, Semaphores. Four different approaches Hardware support Disable interrupts Special instructions Software-defined approaches.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
1 Semaphores Special variable called a semaphore is used for signaling If a process is waiting for a signal, it is suspended until that signal is sent.
Language Support for Concurrency. 2 Common programming errors Process i P(S) CS P(S) Process j V(S) CS V(S) Process k P(S) CS.
Synchronization: Monitors Hank Levy. 6/21/20152 Synchronization with Semaphores Semaphores can be used to solve any of the traditional synchronization.
Semaphores CSCI 444/544 Operating Systems Fall 2008.
CS533 Concepts of Operating Systems Class 3 Monitors.
A. Frank - P. Weisberg Operating Systems Introduction to Cooperating Processes.
Monitors: An Operating System Structuring Concept
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.
Experience with Processes and Monitors in Mesa
Concurrency, Mutual Exclusion and Synchronization.
Semaphores, Locks and Monitors By Samah Ibrahim And Dena Missak.
4061 Session 21 (4/3). Today Thread Synchronization –Condition Variables –Monitors –Read-Write Locks.
Principles of Operating Systems Lecture 6 and 7 - Process Synchronization.
CSC321 Concurrent Programming: §5 Monitors 1 Section 5 Monitors.
Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 7: Process Synchronization Background The Critical-Section Problem Synchronization.
ICS 313: Programming Language Theory Chapter 13: Concurrency.
Chapter 7 -1 CHAPTER 7 PROCESS SYNCHRONIZATION CGS Operating System Concepts UCF, Spring 2004.
Process Synchronization Tanenbaum Ch 2.3, 2.5 Silberschatz Ch 6.
CSE 451: Operating Systems Winter 2012 Semaphores and Monitors Mark Zbikowski Gary Kimura.
Module 2.1: Process Synchronization
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Lecture 6: Monitors & Semaphores. Monitor Contains data and procedures needed to allocate shared resources Accessible only within the monitor No way for.
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.
Fall 2000M.B. Ibáñez Lecture 08 High Level mechanisms for process synchronization Critical Regions Monitors.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-2: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
IT 344: Operating Systems Winter 2008 Module 7 Semaphores and Monitors
1 Previous Lecture Overview  semaphores provide the first high-level synchronization abstraction that is possible to implement efficiently in OS. This.
Process Synchronization. Objectives To introduce the critical-section problem, whose solutions can be used to ensure the consistency of shared data To.
© 2004, D. J. Foreman 1 Monitors and Inter-Process Communication.
OS Winter’03 Concurrency. OS Winter’03 Bakery algorithm of Lamport  Critical section algorithm for any n>1  Each time a process is requesting an entry.
“Language Mechanism for Synchronization”
Process Synchronization
CS533 Concepts of Operating Systems Class 3
Chapter 5: Process Synchronization
CS510 Operating System Foundations
Lecture 25 Syed Mansoor Sarwar
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
CS533 Concepts of Operating Systems Class 3
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
Thread Synchronization including Mutual Exclusion
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
Synchronization: Monitors
CSE 153 Design of Operating Systems Winter 19
CSE 153 Design of Operating Systems Winter 2019
Chapter 6: Synchronization Tools
CSE 451: Operating Systems Winter Module 7 Semaphores and Monitors
Monitors and Inter-Process Communication
Review The Critical Section problem Peterson’s Algorithm
Presentation transcript:

University of Pennsylvania 9/28/00CSE 3801 Concurrent Programming (Critical Regions, Monitors, and Threads) CSE 380 Lecture Note 6 Insup Lee

University of Pennsylvania 9/28/00CSE 3802 Concurrent Programming An OS consists of a large number of programs that execute asynchronously and cooperate. Traditionally, these programs were written in assembly language for the following reasons: –High-level languages (HLL) did not provide mechanisms for writing machine-dependent code (such as device drivers). –HLL did not provide the appropriate tools for writing concurrent programs. –HLL for concurrent programs were not efficient. HLL for OS must provide facilities for synchronization and modularization. Modularization: describe the partitioning of a single large program into a set of smaller modules. (1) Processes, (2) Procedures, (3) Abstract Data Types (a set of objects, a set of operations)

University of Pennsylvania 9/28/00CSE 3803 Motivating examples P and V operations are better than shared variables but still susceptible to programming errors P(S) P(S). ==>... V(S) P(S) P(S1) P(S1).. P(S2) P(S2). ==>... V(S2) V(S1).. V(S1) V(S2)

University of Pennsylvania 9/28/00CSE 3804 Critical Regions A higher-level programming language construct proposed in 1972 by Brinch Hansen and Hoare.  if a variable is to be shared, it must be declared as such  access to shared variables only in mutual exclusion var a: shared int var b: shared int region a do -- access variable a -- Compiler can generate code using P and V: P(Sa) -- access variable a -- V(Sa)

University of Pennsylvania 9/28/00CSE 3805 Critical Regions aren't perfect Process 1: region a do region b do stmt1; Process 2: region b do region a do stmt2;

University of Pennsylvania 9/28/00CSE 3806 Conditional Critical Regions  Critical regions are basically a mutex  They are not easily adapted to general synchronization problems, i.e. those requiring a counting semaphore  Hoare, again in 1972, proposed conditional critical regions:  region X when B do S  X will be accessed in mutual exclusion in S  process delayed until B becomes true

University of Pennsylvania 9/28/00CSE 3807 The Producer-consumer problem Var buffer: shared record pool: array[0...n-1] of item; count, in, out: integer = 0; Producer: region buffer when count < n do begin pool[in] := item_produced in : = in + 1 mod n count := count + 1 end Consumer: region buffer when count > 0 do begin item_consumed := pool[out] out := out + 1 mod n count := count – 1 end

University of Pennsylvania 9/28/00CSE 3808 Brinch Hansen extension [1972] region v do begin S1 await(B) S2 end  synchronization conditions can be placed anywhere within the region (unlike original proposal)

University of Pennsylvania 9/28/00CSE 3809 Monitors A monitor is a shared data object together with a set of operations to manipulate it. To enforce mutual exclusion, at most one process may execute operations defined for the data object at any given time. All uses of shared variables are governed by monitors. –Support data abstraction (hide implementation details) –Only one process may execute a monitor's procedure at a time –data type “condition” for synchronization (can be waited or signaled within a monitor procedure) –Two operations on “condition” variables: wait: Forces the caller to be delayed. Exclusion released. Hidden Q of waiters. signal: One waiting process is resumed if there are waiters, and is not remembered.

University of Pennsylvania 9/28/00CSE fast q | | | | | | | | process - entrance at a time - q - - | | | | | | | | | | cond q cond q

University of Pennsylvania 9/28/00CSE Semaphore using monitor type semaphore = monitor var busy: boolean | nonbusy: condition procedure entry P begin if busy then nonbusy.wait fi busy := true end {P} procedure entry V begin busy := false nonbusy.signal end {V} begin busy := false end {monitor}