⇰ MONITOR :-
The monitor is one of the way of achieving synchronization. The monitor is supported by programming languages to achieve mutual exclusion between processes. Although semaphores provide a convenient and effective mechanism for process synchronization, but using semaphore incorrectly can cause timing errors that are difficult to detect.
A monitor is a synchronization construct that allows threads to have both mutual exclusion and the ability to work or block for a certain condition to become true. Monitors also have a machenism for singling other threads that their condition has been met. Monitors provide a machenism for threads to temporarily give up exclusive access in order to wait for some condition to be met.
Another definition of monitor is a thread-safe class, object or module that wraps around a mutex in order to safely allow access to a method or variable by more than ane thread. The defining charactorstics of a monitor is that its methods are executed with mutual exclusion. At each point of time, at most one thread may be executing any of its methods. By using one or more condition variable it can also provide the ability for threads to wait on a certain condition.
Monitor have the advantage of making parallel programming easier and less error prone than using other technique such as semaphore. Monitor is basically abstract data type and may contain shared data variables and procedures. It allow a single process to access the shared data variables at a time.
⇰ IMPORTANT POINTS :-
i> Monitor is the collection of condition variables and procedures which are combined in a special kind of module or a package.
ii> The processes that are running outside the monitor can never access the internal variable of the monitor.
iii> Only one process at a time can execute code inside monitors.
⇰ SYNTAX OF MONITOR :-
monitor < monitor name >
{
variables ;
procedure P1 (.....)
{
............
}
procedure P2 (.....)
{
............
}
procedure P3 (.....)
{
............
}
Initialization code (.....)
{
...........
}
}
click here for post on semaphore.
Share, Follow and please comment if you find anything incorrect or to share more information about the topic discussed above.
Share, Follow and please comment if you find anything incorrect or to share more information about the topic discussed above.
Comments
Post a Comment
Please comment.