The monitor is one of the ways to achieve Process synchronization. The monitor is supported by programming languages to achieve mutual exclusion between processes. For example Java Synchronized methods. Java provides wait() and notify() constructs.
- 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 the monitor but can call procedures of the monitor.
- Only one process at a time can execute code inside monitors.
Two different operations are performed on the condition variables of the monitor.
let say we have 2 condition variables
condition x, y; // Declaring variable
x.wait() : Process performing wait operation on any condition variable are suspended. The suspended processes are placed in block queue of that condition variable.
Note: Each condition variable has its unique block queue.
x.signal(): When a process performs signal operation on condition variable, one of the blocked processes is given chance.
If (x block queue empty) // Ignore signal else // Resume a process from block queue.
Advantages of Monitor:
Monitors have the advantage of making parallel programming easier and less error prone than using techniques such as semaphore.
Disadvantages of Monitor:
Monitors have to be implemented as part of the programming language . The compiler must generate code for them. This gives the compiler the additional burden of having to know what operating system facilities are available to control access to critical sections in concurrent processes. Some languages that do support monitors are Java,C#,Visual Basic,Ada and concurrent Euclid.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Process Synchronization | Set 2
- Introduction of Process Synchronization
- Semaphores in Process Synchronization
- Dekker's algorithm in Process Synchronization
- Peterson's Algorithm in Process Synchronization
- Bakery Algorithm in Process Synchronization
- Sleeping Barber problem in Process Synchronization
- Dining-Philosophers Solution Using Monitors
- Reader-Writers solution using Monitors
- Reader-Writer problem using Monitors (pthreads)
- Process Table and Process Control Block (PCB)
- Pass the value from child process to parent process
- Process states and Transitions in a UNIX Process
- Process Scheduler : Job and Process Status
- Critical Section in Synchronization
- Synchronization in Distributed Systems
- Mutual Exclusion in Synchronization
- Priority Inheritance Protocol (PIP) in Synchronization
- Lock Variable Synchronization Mechanism
- Difference between Process Image and Multi Thread Process image
Improved By : shivanshukumarsingh1