Skip to main content
Engineering LibreTexts

10.4.2: IPC - Monitors

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    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

    This page titled 10.4.2: IPC - Monitors is shared under a CC BY-SA license and was authored, remixed, and/or curated by Patrick McClanahan.

    • Was this article helpful?