Skip to main content
Engineering LibreTexts

5.4.2: IPC - Monitors

  • Page ID
    47661
  • Monitors in Process Synchronization

    The monitor is one of the ways to achieve process synchronization. The monitor is supported by programming languages to achieve mutual exclusion between processes. Not all programming languages provide for monitors. 

    The proper basic usage of a monitor is: (the italicized text are all comments explaining what is going on)

    acquire(m); // Acquire this monitor's lock - this prevents other processes from being able to enter the critical section.
    while (!condition) { // While the condition that we are waiting for is not true (in programming the ! means NOT)
    	wait(m, condition); // Wait on this monitor's lock (tht is the variable m) and condition variable.
    }
    // ... Critical section of code goes here ...
    signal(condition2); // condition2 might be the same as condition or different.
    release(m); // Release this monitor's lock, now one of the processes sitting in the wait() function, can be run

    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.

    Adapted from:
    "Monitors in Process Synchronization" by shivanshukumarsingh1Geeks for Geeks is licensed under CC BY-SA 4.0
    "Monitor (synchronization)" by Multiple ContributorsWikipedia is licensed under CC BY-SA 3.0

    • Was this article helpful?