Monitors in Process Synchronization (original) (raw)

Last Updated : 11 May, 2026

Monitors are a high-level synchronization mechanism that simplify process and thread synchronization. They are built on top of locks and are mostly used in multithreading systems like Java.

Unlike semaphores, where the programmer must explicitly call wait() and signal(), monitors combine shared data and the operations on that data inside a single structure, making synchronization safer and easier to manage.

Implementation of Monitors

class

Structure of Monitor

Condition Variables in Monitors

A condition variable allows threads to wait until a certain condition becomes true. They are always used inside a monitor. There are three main condition variables:

**Pseudocode for monitors:

class AccountUpdate {

private int bal;
condition sufficientFunds; // condition variable

void synchronized deposit(int n) {

// increase balance
// signal waiting threads that funds are available
}

void synchronized withdraw(int n) {
// if (bal < n) -> wait on sufficientFunds
// else -> perform withdrawal (bal = bal - n)
}

}

Example: Monitor Implementation in Java

Here is a simple example of a Bank Account Monitor which will have two features (deposit and withdraw) using Java:

Java `

class AccountUpdate { private int bal;

void synchronized deposit(int n) {
    bal = bal + n;
}

void synchronized withdraw(int n) {
    bal = bal - n;
}

}

`

**Code Explanation

Limitations of Monitors