Docsity

Concurrent Programming with Monitors: Shared Data Synchronization, Slides of Object Oriented Analysis and Design

Partial preview of the text

Download Concurrent Programming with Monitors: Shared Data Synchronization and more Slides Object Oriented Analysis and Design in PDF only on Docsity!

Ch. 4 1

Concurrent software

• The case of a module defining shared data• E.g., abstract object BUFFER

  • module QUEUE_OF_CHAR is

GENERIC_FIFO_QUEUE (CHAR)

  • BUFFER : QUEUE_OF_CHAR.QUEUE

with operations

  • PUT: inserts a character in BUFFER– GET: extracts a character from BUFFER– NOT_FULL: returns true if BUFFER not full– NOT_EMPTY: returns true if BUFFER not empty

Ch. 4 2

How to control correctaccess to shared data?

• Not sufficient that clients check

operation invocations, such as

if QUEUE_OF_CHAR.NOT_FULL (BUFFER) then

QUEUE_OF_CHAR.PUT (X, BUFFER);

end if;

• Consumer_1 and Consumer_2 might do

this concurrently

  • if only one slot is left, both may find the buffer

not full, the first who writes fills it, and theother writes in a full buffer

Ch. 4 4

Monitors

• Abstract objects used in a concurrent

environment

• Available in the Java programming

language

Ch. 4 5

Monitors: an example

concurrent module

CHAR_BUFFER

This is a monitor, i.e., an abstract object module in a concurrent environment uses

exports procedure

PUT (C :

in

CHAR)

requires

NOT_FULL;

procedure

GET (C:

out

CHAR)

requires

NOT_EMPTY;

NOT_EMPTY and NOT_FULL are hidden Boolean functions yielding TRUE if the buffer is not empty and not full, respectively. They are not exported as operations, because their purpose is only to delay the calls to PUT and GET if they are issued when the buffer is in a state where itcannot accept them... end

CHAR_BUFFER

Ch. 4 7

Monitor types: an example

generic concurrent module

GENERIC_FIFO_QUEUE (EL)

This is a generic monitor type, i.e., an abstract data typeaccessed in a concurrent environment

uses

exports

type

QUEUE: ?;

procedure

PUT (Q1:

in out

QUEUE; E1:

in

EL)

requires

NOT_FULL (Q1: QUEUE);

procedure

GET (Q2:

in out

QUEUE; E2:

out

EL)

requires

NOT_EMPTY(Q2: QUEUE);

...

end

GENERIC_FIFO_QUEUE (EL)