Monitor

1. Monitor

  • high-level synchronization construct that allows the safe-sharing of an abstract data type among concurrent processes
monitor monitor-name{
    shared variable declarations
    procedure body p1(){}
    procedure body p2() {}
    procedure body pn() {}
    {
        initialization code
    }
}
2. Schematic View of a Monitor

  • the monitor construct ensures that at most one process can be active within the monitor at a given time
  • shred data (local variables) of the monitor can be accessed only by local procedure

3. Monitors Introduction

  • to allow a process to wait within the monitor
    • a condition variable must be declared, as condition x, y
  • condition variable can only be used with the operation wait and signal
    • the operation 
      • x.wait() means that the process invoking this operation is suspended until another process invokes x..signal()
      • x.signal() operation resumes exactly one suspend process on condition variable x. If no process is suspended on condition variable x, then the signal operation has no effect.
      • wait and signal operations of the monitors are not the same as semaphore wait and signal operations
4. Monitor with condition variables
  • when a process P signal to wake up process Q that was waiting on a condition, potentially both of them can be active.
  • however, monitor rules require that at most one process can be active within the monitor
    • signal and wait: P waits until Q leaves the monitor
    • signal and continue: Q waits until P leaves the monitor (or, until P waits for another condition)
    • Signal and leave: P has to leave the monitor after signaling
  • the design decision is different for different programming languages
5. Procedure-Consumer Problem With Monitor

6. Dining-Phisolophers Problem with Monitors

Leave a Reply

Your email address will not be published. Required fields are marked *

*