Monitor in OS

by Anup Maurya
11 minutes read

Monitor is a tool, which help us to achieve process synchronization. Programming languages help the monitor to accomplish mutual exclusion between different activities in a system.

What is a monitor in OS?

A monitor in an operating system is a synchronization mechanism that helps regulate access to shared data. It acts as a package containing shared data structures and operations, allowing for synchronization between concurrent process calls. Monitors are commonly used to achieve mutual exclusion and coordinate interactions among different activities in a system. Several programming languages, including Java, C#, Visual Basic, Ada, and concurrent Euclid, support the use of monitors.

Processes external to the monitor cannot directly access its internal variables but can make use of the monitor’s procedures.

For example, Java provides synchronization methods such as wait() and notify() for this purpose.

Syntax of monitor in OS

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

Monitor monitorName{
    procedure p1{ ... };
    procedure p2{ ... };
    procedure pn{ ... };

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

The characteristics of monitors in an operating system are as follows:

  1. Exclusive Execution: Only one program can execute inside the monitor at any given time.
  2. Grouped Methods and Fields: Monitors are defined as a collection of methods and fields, encapsulated within a special package in the OS.
  3. Limited Access to Internal Variables: Programs running outside the monitor cannot directly access its internal variables, but they can make use of the monitor’s functions.
  4. Simplified Synchronization: Monitors were designed to simplify synchronization problems in concurrent programming.
  5. High-Level Synchronization: Monitors offer a higher level of synchronization between processes, making it easier to manage shared resources in a controlled manner.

Components of Monitor in an operating system

The components of a monitor in an operating system consist of:

  1. Initialization: This part includes the code for initializing the monitor, which is executed only once during the creation of the monitor.
  2. Private Data: Monitors utilize this feature to keep data private. It encompasses all the monitor’s internal data, including private functions that are accessible only within the monitor. As a result, private fields and functions remain hidden from outside access.
  3. Monitor Procedures: These are procedures or functions that can be invoked from outside the monitor, allowing external programs to interact with the monitor’s functionalities.
  4. Monitor Entry Queue: An essential component of the monitor is the Monitor Entry Queue, which maintains a list of threads (often referred to as procedures) waiting to access the monitor. This queue ensures that only one thread executes within the monitor at a time, providing synchronized access to shared resources.

Advantages of Monitors in OS

  1. Simpler and Safer Concurrent Programming: Monitors make concurrent or parallel programming more straightforward and less error-prone compared to semaphore-based solutions.
  2. Effective Process Synchronization: Monitors facilitate process synchronization in the operating system, ensuring orderly access to shared resources.
  3. Built-in Mutual Exclusion: Monitors inherently provide mutual exclusion, preventing multiple processes from accessing critical sections simultaneously.
  4. Ease of Setup: Implementing monitors is generally easier than dealing with semaphores, simplifying the development of synchronized code.
  5. Improved Timing Handling: Monitors may offer better handling of timing-related issues compared to semaphores, leading to more reliable synchronization.

Disadvantages of Monitors in OS

  1. Language Dependency: Monitors need to be implemented using the features provided by the programming language, limiting their portability across different languages.
  2. Increased Compiler Workload: Monitors may impose additional burden on the compiler, potentially affecting compilation time and complexity.
  3. Awareness of OS Features: Utilizing monitors effectively requires understanding the available operating system features for controlling critical sections in parallel procedures, which can be a learning curve for developers.

related posts

Leave a Comment