Open In App

Monitors in Process Synchronization

Last Updated : 24 Mar, 2023
Like Article

Monitors are a higher-level synchronization construct that simplifies process synchronization by providing a high-level abstraction for data access and synchronization. Monitors are implemented as programming language constructs, typically in object-oriented languages, and provide mutual exclusion, condition variables, and data encapsulation in a single construct.

  1. A monitor is essentially a module that encapsulates a shared resource and provides access to that resource through a set of procedures. The procedures provided by a monitor ensure that only one process can access the shared resource at any given time, and that processes waiting for the resource are suspended until it becomes available.
  2. Monitors are used to simplify the implementation of concurrent programs by providing a higher-level abstraction that hides the details of synchronization. Monitors provide a structured way of sharing data and synchronization information, and eliminate the need for complex synchronization primitives such as semaphores and locks.
  3. The key advantage of using monitors for process synchronization is that they provide a simple, high-level abstraction that can be used to implement complex concurrent systems. Monitors also ensure that synchronization is encapsulated within the module, making it easier to reason about the correctness of the system.

However, monitors have some limitations. For example, they can be less efficient than lower-level synchronization primitives such as semaphores and locks, as they may involve additional overhead due to their higher-level abstraction. Additionally, monitors may not be suitable for all types of synchronization problems, and in some cases, lower-level primitives may be required for optimal performance.

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. 

  1. It is the collection of condition variables and procedures combined together in a special kind of module or a package.
  2. The processes running outside the monitor can’t access the internal variable of the monitor but can call procedures of the monitor.
  3. Only one process at a time can execute code inside monitors.

Syntax: monitors Condition Variables: Two different operations are performed on the condition variables of the monitor.


let say we have 2 condition variables condition x, y; // Declaring variable   Wait operation 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.   Signal operation 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
  // 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.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads