ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-2: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.

Slides:



Advertisements
Similar presentations
1 Interprocess Communication 1. Ways of passing information 2. Guarded critical activities (e.g. updating shared data) 3. Proper sequencing in case of.
Advertisements

Ch 7 B.
Chapter 2 Processes and Threads
Chapter 6: Process Synchronization
02/27/2004CSCI 315 Operating Systems Design1 Process Synchronization Deadlock Notice: The slides for this lecture have been largely based on those accompanying.
Monitors A high-level abstraction that provides a convenient and effective mechanism for process synchronization Only one process may be active within.
6.5 Semaphore Can only be accessed via two indivisible (atomic) operations wait (S) { while S
Chapter 6 Process Synchronization: Part 2. Problems with Semaphores Correct use of semaphore operations may not be easy: –Suppose semaphore variable called.
Monitors Chapter 7. The semaphore is a low-level primitive because it is unstructured. If we were to build a large system using semaphores alone, the.
DPNM Lab. Dept. of CSE, POSTECH
Informationsteknologi Wednesday, September 26, 2007 Computer Systems/Operating Systems - Class 91 Today’s class Mutual exclusion and synchronization 
Synchronization Principles Gordon College Stephen Brinton.
1 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
02/19/2010CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
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.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Process Synchronization (Or The “Joys” of Concurrent.
CS444/CS544 Operating Systems Synchronization 2/21/2007 Prof. Searleman
Chapter 6 – Concurrent Programming Outline 6.1 Introduction 6.2Monitors 6.2.1Condition Variables 6.2.2Simple Resource Allocation with Monitors 6.2.3Monitor.
02/25/2004CSCI 315 Operating Systems Design1 Process Synchronization Notice: The slides for this lecture have been largely based on those accompanying.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Module 6: Process Synchronization.
Semaphores. Readings r Silbershatz: Chapter 6 Mutual Exclusion in Critical Sections.
Chapter 6: Process Synchronization. 6.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 8, 2005 Background Concurrent.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-1: I/O Management Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 8-2: I/O Management (Review) Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Monitors High-level synchronization construct that allows the safe sharing of an abstract data type among concurrent processes. monitor monitor-name {
ITEC 502 컴퓨터 시스템 및 실습 Chapter 1: Introduction. ITEC 502 컴퓨터 시스템 및 실습 Chapter 1: Introduction Mi-Jung Choi DPNM Lab. Dept. of CSE,
5.1 Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Problems with Semaphores Incorrect use of semaphore operations:
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.
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 Concurrency: Mutual Exclusion and Synchronization Chapter 5.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
1 Interprocess Communication (IPC) - Outline Problem: Race condition Solution: Mutual exclusion –Disabling interrupts; –Lock variables; –Strict alternation.
Chapter 5 Concurrency: Mutual Exclusion and Synchronization Operating Systems: Internals and Design Principles, 6/E William Stallings Patricia Roy Manatee.
Chapter 6: Process Synchronization. Module 6: Process Synchronization Background The Critical-Section Problem Peterson’s Solution Synchronization Hardware.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 11-1: File Systems Implementation Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 24 Critical Regions.
Operating Systems Inter-Process Communications. Lunch time in the Philosophy Department. Dining Philosophers Problem (1)
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.
Operating Systems Lecture Notes Synchronization Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 9-1: Disk Scheduling Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 10-2: File Systems Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
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.
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-3: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
Chapter 71 Monitor for Reader/Writers  Synchronizes access if all processes follow.  If some don’t go through monitor and database is accessed directly,
ITEC 502 컴퓨터 시스템 및 실습 Chapter 2-2: Threads Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH.
6.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Q: 請以實際例子說明 critical section 之意 ? 何謂 race condition? while (true) { /*
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 6: Process Synchronization.
Deadlock and Starvation
Semaphore Synchronization tool that provides more sophisticated ways (than Mutex locks) for process to synchronize their activities. Semaphore S – integer.
Chapter 5: Process Synchronization – Part 3
Auburn University COMP 3500 Introduction to Operating Systems Synchronization: Part 4 Classical Synchronization Problems.
Background on the need for Synchronization
Chapter 5: Process Synchronization
Deadlock and Starvation
CSCI 511 Operating Systems Chapter 5 (Part C) Monitor
Chapter 5: Process Synchronization
Concurrency: Mutual Exclusion and Synchronization
Chapter 5: Process Synchronization (Con’t)
Lecture 25 Syed Mansoor Sarwar
Semaphore Originally called P() and V() wait (S) { while S <= 0
Process Synchronization
Critical section problem
DPNM Lab. Dept. of CSE, POSTECH
Chapter 6 Synchronization Principles
Monitors and Inter-Process Communication
Presentation transcript:

ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-2: Process Synchronization Mi-Jung Choi DPNM Lab. Dept. of CSE, POSTECH

ITEC502 컴퓨터 시스템 및 실습 2 Contents 1.Monitors 2.Message Passing 3.Barriers

ITEC502 컴퓨터 시스템 및 실습 3 Problems with Semaphores  Be careful not to misuse the semaphore  Examples of misuse: –mutex is a semaphore which is initialized to 1 –signal (mutex) …. wait (mutex) results in a violation of the mutual exclusion requirement –wait (mutex) … wait (mutex) results in deadlock –Omitting of wait (mutex) or signal (mutex) (or both) Either mutual exclusion is violated or a deadlock will occur  To deal with such errors, the monitor may be used

ITEC502 컴퓨터 시스템 및 실습 4 Monitors - Concept  A high-level abstraction that provides a convenient and effective mechanism for process synchronization  Monitor is defined as an abstract data type like class in object-oriented language (C++, Java)  A monitor instance is shared among multiple processes  Only one process may be active within the monitor at a time monitor monitor-name { shared variable declarations procedure P 1 (…) { …. } … procedure P n (…) {……} Initialization code ( ….) { … } } Private Data Public Methods Initialization Method

ITEC502 컴퓨터 시스템 및 실습 5 Schematic view of a Monitor  Shared data  Operations  Initialization code  The shared data can be accessed by operations  Only one process is active within a monitor at a time  Programmer don’t need to code this synchronization

ITEC502 컴퓨터 시스템 및 실습 6 Condition Variables  Basic monitor is not sufficiently powerful for modeling some synchronization schemes  To solve, condition variables are introduced –condition x, y; –A programmer can define one or more variables of type condition  Two operations on a condition variable: –x.wait () – a process that invokes the operation is suspended –x.signal () – resumes one of processes (if any) that invoked x.wait () –x.signal() resumes exactly one suspended process –If no process is suspended, then nothing happens

ITEC502 컴퓨터 시스템 및 실습 7 Monitor with Condition Variables

ITEC502 컴퓨터 시스템 및 실습 8 Condition Variables – issues  Suppose that, when the x.signal() is invoked by a process P, there is a suspended process Q with condition x  If the suspended process Q is allowed to resume its execution, the signaling process P must wait –Otherwise both Q and P would be active simultaneously  Two possibilities: –Signal and Wait: P either waits until Q leaves the monitor or waits for another condition –Signal and Continue: Q either waits until P leaves the monitor or waits for another condition

ITEC502 컴퓨터 시스템 및 실습 9 Monitors (1) Example of a monitor

ITEC502 컴퓨터 시스템 및 실습 10 Monitors (2)  Outline of producer-consumer problem with monitors –only one monitor procedure active at one time –buffer has N slots

ITEC502 컴퓨터 시스템 및 실습 11 Monitors (3) Solution to producer-consumer problem in Java (part 1)

ITEC502 컴퓨터 시스템 및 실습 12 Monitors (4) Solution to producer-consumer problem in Java (part 2)

ITEC502 컴퓨터 시스템 및 실습 13 Message Passing The producer-consumer problem with N messages

ITEC502 컴퓨터 시스템 및 실습 14 Barriers  Use of a barrier –processes approaching a barrier –all processes but one blocked at barrier –last process arrives, all are let through

ITEC502 컴퓨터 시스템 및 실습 15 Summary  To deal with errors of semaphores, the monitor may be used  Monitors provides the synchronization mechanism for sharing abstract data types –Condition variables provides a method by which a monitor procedure can block its execution until it is signaled to continue