You are on page 1of 8

MONITOR

T.KARTHEESWARI
20pa12
11/20/2020 1
What is a monitor?
A collection of data and procedures.
Mutual exclusion.
-Allows controlled acquisition and release of
critical resources.
-Single anonymous lock automatically acquired
and released at entry and exit.
• Data encapsulation
-Monitor procedures are “ entry points” for
accessing data.

11/20/2020 2
Monitor
A high-level abstraction that provides a convenient and
effective mechanism for process synchronization.
Abstract data type, internal variables only accessible by code
with in the procedure.
Only one process may be active with in the monitor at a time.
But not powerful enough to model some synchronization
schemes.
monitor monitor-name
{ //shared variable declarations.
procedure p1(….) {…}
procedure pn(…) {…}
initialization code (…){…}
}

11/20/2020 3
Rule to follow with monitors
Any process can call a monitor procedure at any time.
But only one process can be inside a monitor at any
time (mutual exclusion).
No process can directly access a monitor’s local
variables (data encapsulation).
A monitor may only access its local variables.

11/20/2020 4
What problems do monitors solve?
Mutual exclusion.
Encapsulation of data.
Compiler can automatically scan program text for
some types of synchronization bugs.
Synchronization of shared data access simplified vs.
semaphores and locks.
Good for problems that require course granularity.

11/20/2020 5
Runtime system calls for monitors:
Enter monitor {guarantee mutual exclusion}
Exitmonitor {hit the road, letting someone else run}
Wait {step out until condition satisfied}
Signal { if someone’s waiting step out and let him run}

Entermontior and exitmonitor are inserted


automatically by the compiler.
This guarantees mutual exclusion for code inside of the
monitor.
11/20/2020 6
Monitor- summary.
Language supports monitors.
Compiler understands them.
Compiler inserts call to runtime routines for.
 Monitor entry.
 Monitor exit.
• Programmer inserts calls to runtime routines for
 Signal.
 Wait.
• Runtime system implements these routines.
-Moves threads on and off queues.
-Ensures mutual exclusion.
11/20/2020 7
THANK YOU

20pa12 8

You might also like