ch5 - Chapter 5 Monitors & Condition Synchronization...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Concurrency: monitors & condition synchronization 1 ©Magee/Kramer 2 nd Edition Chapter 5 Monitors & Condition Synchronization
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Concurrency: monitors & condition synchronization 2 ©Magee/Kramer 2 nd Edition monitors & condition synchronization Concepts : monitors : encapsulated data + access procedures mutual exclusion + condition synchronization single access procedure active in the monitor nested monitors Models : guarded actions Practice : private data and synchronized methods (exclusion). wait(), notify() and notifyAll() for condition synch. single thread active in the monitor at a time
Background image of page 2
Concurrency: monitors & condition synchronization 3 ©Magee/Kramer 2 nd Edition 5.1 Condition synchronization A controller is required for a carpark, which only permits cars to enter when the carpark is not full and does not permit cars to leave when there are no cars in the carpark. Car arrival and departure are simulated by separate threads.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Concurrency: monitors & condition synchronization 4 ©Magee/Kramer 2 nd Edition carpark model Events or actions of interest? arrive and depart Identify processes. arrivals, departures and carpark control Define each process and interactions (structure). ARRIVALS CARPARK CONTROL DEPARTURES arrive depart CARPARK
Background image of page 4
Concurrency: monitors & condition synchronization 5 ©Magee/Kramer 2 nd Edition carpark model CARPARKCONTROL(N=4) = SPACES[N], SPACES[i:0. .N] = ( when(i>0) arrive->SPACES[i-1] | when(i<N) depart->SPACES[i+1] ). ARRIVALS = (arrive->ARRIVALS). DEPARTURES = (depart->DEPARTURES). ||CARPARK = (ARRIVALS||CARPARKCONTROL(4)||DEPARTURES). Guarded actions are used to control arrive and depart . LTS?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Concurrency: monitors & condition synchronization 6 ©Magee/Kramer 2 nd Edition carpark program Model - all entities are processes interacting by actions Program - need to identify threads and monitors thread - active entity which initiates (output) actions monitor - passive entity which responds to (input) actions. For the carpark? ARRIVALS CARPARK CONTROL DEPARTURES arrive depart CARPARK
Background image of page 6
Concurrency: monitors & condition synchronization 7 ©Magee/Kramer 2 nd Edition carpark program - class diagram Applet Runnable ThreadPanel CarParkControl Arrivals Departures DisplayCarPark CarParkCanvas CarPark arrivals, departures arrive() depart() carDisplay carpark disp We have omitted DisplayThread and GraphicCanvas threads managed by ThreadPanel .
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Concurrency: monitors & condition synchronization 8 ©Magee/Kramer 2 nd Edition public void start() { CarParkControl c = new DisplayCarPark(carDisplay,Places); arrivals.start( new Arrivals(c)); departures.start( new Departures(c)); } carpark program Arrivals and Departures implement Runnable , CarParkControl provides the control (condition synchronization). Instances of these are created by the start() method of the CarPark applet :
Background image of page 8
Concurrency: monitors & condition synchronization 9 ©Magee/Kramer 2 nd Edition carpark program - Arrivals and Departures threads class Arrivals implements Runnable { CarParkControl carpark; Arrivals(CarParkControl c) {carpark = c;} public void run() { try { while (true) { ThreadPanel.rotate(330); carpark. arrive (); ThreadPanel.rotate(30);
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 40

ch5 - Chapter 5 Monitors &amp; Condition Synchronization...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online