Monitor in OS

Learn via video courses
Topics Covered

Overview

Monitor in an operating system is one method for achieving process synchronization. Programming languages help the monitor to accomplish mutual exclusion between different activities in a system. wait() and notify() constructs are synchronization functions that are available in the Java programming language.

What is a Monitor in OS?

Monitors are a programming language component that aids in the regulation of shared data access. The Monitor is a package that contains shared data structures, operations, and synchronization between concurrent procedure calls. Therefore, a monitor is also known as a synchronization tool. Java, C#, Visual Basic, Ada, and concurrent Euclid are among some of the languages that allow the use of monitors. Processes operating outside the monitor can't access the monitor's internal variables, but they can call the monitor's procedures.

For example, synchronization methods like the wait() and notify() constructs are available in the Java programming language.

Syntax of Monitor in OS

Monitor in OS has a simple syntax similar to how we define a class, it is as follows:

Monitor in an operating system is simply a class containing variable_declarations, condition_variables, various procedures (functions), and an initializing_code block that is used for process synchronization.

Characteristics of Monitors in OS

A monitor in OS has the following characteristics:

  • We can only run one program at a time inside the monitor.
  • Monitors in an operating system are defined as a group of methods and fields that are combined with a special type of package in the OS.
  • A program cannot access the monitor's internal variable if it is running outside the monitor. However, a program can call the monitor's functions.
  • Monitors were created to make synchronization problems less complicated.
  • Monitors provide a high level of synchronization between processes.

Components of Monitor in an Operating System

The monitor is made up of four primary parts:

  1. Initialization: The code for initialization is included in the package, and we just need it once when creating the monitors.
  2. Private Data: It is a feature of the monitor in an operating system to make the data private. It holds all of the monitor's secret data, which includes private functions that may only be utilized within the monitor. As a result, private fields and functions are not visible outside of the monitor.
  3. Monitor Procedure: Procedures or functions that can be invoked from outside of the monitor are known as monitor procedures.
  4. Monitor Entry Queue: Another important component of the monitor is the Monitor Entry Queue. It contains all of the threads, which are commonly referred to as procedures only.

Condition Variables

There are two sorts of operations we can perform on the monitor's condition variables:

  1. Wait
  2. Signal

Consider a condition variable (y) is declared in the monitor:

y.wait(): The activity/process that applies the wait operation on a condition variable will be suspended, and the suspended process is located in the condition variable's block queue.

y.signal(): If an activity/process applies the signal action on the condition variable, then one of the blocked activity/processes in the monitor is given a chance to execute.

Advantages of Monitor in OS

  • Monitors offer the benefit of making concurrent or parallel programming easier and less error-prone than semaphore-based solutions.
  • It helps in process synchronization in the operating system.
  • Monitors have built-in mutual exclusion.
  • Monitors are easier to set up than semaphores.
  • Monitors may be able to correct for the timing faults that semaphores cause.

Disadvantages of Monitor in OS

  • Monitors must be implemented with the programming language.
  • Monitor increases the compiler's workload.
  • The monitor requires to understand what operating system features are available for controlling crucial sections in the parallel procedures.

Conclusion

  • Monitor in an operating system is one method for achieving process synchronization.
  • Monitors in OS offer the benefit of making concurrent or parallel programming easier and less error-prone than semaphore-based solutions.
  • The monitor is made up of four primary parts, Initialization, Private Data, Monitor Procedure, and Monitor Entry Queue.
  • wait() and signal() are two methods that we can use with the monitor's condition variables.