ch5 - Concurrency: monitors & condition synchronization...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Concurrency: monitors & condition synchronization 1 ©Magee/Kramer 2 nd Edition Chapter 5 Monitors & Condition Synchronization 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 Concurrency: monitors & condition synchronization 3 ©Magee/Kramer 2 nd Edition 5.1 Condition synchronization A c o ntro lle r is re q uire d fo r a c a rpa rk, whic h o nly pe rm its c a rs to e nte r whe n the c a rpa rk is no t full a nd do e s no t pe rm it c a rs to le a ve whe n the re a re no c a rs in the c a rpa rk. C a r a rriva l a nd de pa rture a re s im ula te d b y s e pa ra te thre a ds . Concurrency: monitors & condition synchronization 4 ©Magee/Kramer 2 nd Edition carpark model ♦ Eve nts o r a c tio ns o f inte re s t? a rrive a nd de pa rt ♦ Ide ntify pro c e s s e s . a rriva ls , de pa rture s a nd c a rpa rk c o ntro l ♦ De fine e a c h pro c e s s a nd inte ra c tio ns (s truc ture ). ARRIVALS CARPARK CONTROL DEPARTURES arrive depart CARPARK 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). G ua rde d a c tio ns a re us e d to c o ntro l arrive a nd depart . LTS? 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 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 . 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...
View Full Document

This note was uploaded on 10/11/2010 for the course COS COS226 taught by Professor Klazar during the Spring '10 term at University of Pretoria.

Page1 / 40

ch5 - Concurrency: monitors & condition synchronization...

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

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