0% found this document useful (0 votes)
13 views2 pages

MONITORS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

MONITORS

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

MONITORS:

 Monitor is one of the ways to achieve Process synchronization. Monitor is


supported by programming languages to achieve mutual exclusion between processes.
 It is the collection of condition variables and procedures combined together in a
special kind of module or a package.
 The processes running outside the monitor can’t access the internal variable of
monitor but can call procedures of the monitor.
 Only one process at a time can execute code inside monitors.
 The monitor is a programming-language construct that provides equivalent
functionality to that of semaphores and that is easier to control.
 Even though both the semaphores and monitors are used to achieve mutual exclusion
in parallel programming environments, they differ in the techniques used to achieve
this task. In monitors, the code that is used to achieve mutual exclusion is in a
single place and is more structured, while code for semaphores are distributed as wait
and signal function calls. Also, it is very easy to make mistakes when implementing
semaphores, while there is a very little chance to make mistakes when implementing
monitors. Further, monitors use condition variables, while semaphores do not.
 Monitor is a programming language construct that is also used to avoid multiple
processes accessing a common resource at the same time therefore guarantees mutual
exclusion. Monitors use conditional variables to achieve this task.
 It has also been implemented as a program library. This allows programmers to put
monitor locks on any object.
 It is characterized as a set of programmer defined operators. Its representation consists
of declaring of variables, whose value defines the state of an instance.
 The representation of a monitor type cannot be used directly by the various processes.
Thus, a procedure defined within a monitor can access only those variables declared
locally within the monitor and its formal parameters.
 Similarly, the local variables of a monitor can be accessed by only the local
procedures. The syntax of monitor is as follows.

monitor monitor_name
{
//Shared variable declarations
Procedure body P1 (………) {
........
}
Procedure body P2 (………) {
........
}
.
.
Procedure body Pn (………) {
........
}
{
Initialization Code
}
}
1
Condition Variables:
Condition variables are synchronization primitives that enable threads to wait until a
particular condition occurs.
Two different operations are performed on the condition variables of the monitor:
1) Wait.
2) Signal.
Let us say we have 2 condition variables condition x, y; //Declaring variable

Wait operation:
x.wait (): Process performing wait operation on any condition variable is
suspended. The suspended processes are placed in block queue of that condition
variable.

Signal operation:
x.signal (): When a process performs signal operation on condition variable, one of the
blocked processes is given chance.
Schematic View of a Monitor:

Monitor With Condition Variables:

You might also like