Download presentation
Presentation is loading. Please wait.
Published byFlora Bond Modified over 8 years ago
1
ITEC 502 컴퓨터 시스템 및 실습 Chapter 3-2: Process Synchronization Mi-Jung Choi mjchoi@postech.ac.kr DPNM Lab. Dept. of CSE, POSTECH
2
ITEC502 컴퓨터 시스템 및 실습 2 Contents 1.Monitors 2.Message Passing 3.Barriers
3
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
4
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
5
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
6
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
7
ITEC502 컴퓨터 시스템 및 실습 7 Monitor with Condition Variables
8
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
9
ITEC502 컴퓨터 시스템 및 실습 9 Monitors (1) Example of a monitor
10
ITEC502 컴퓨터 시스템 및 실습 10 Monitors (2) Outline of producer-consumer problem with monitors –only one monitor procedure active at one time –buffer has N slots
11
ITEC502 컴퓨터 시스템 및 실습 11 Monitors (3) Solution to producer-consumer problem in Java (part 1)
12
ITEC502 컴퓨터 시스템 및 실습 12 Monitors (4) Solution to producer-consumer problem in Java (part 2)
13
ITEC502 컴퓨터 시스템 및 실습 13 Message Passing The producer-consumer problem with N messages
14
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
15
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.