Definition:

  • Ensures only 1 process at a time is active within the monitor
    • when process assume control of monitor, only it can read/write the shared data
    • when process joins the queue (want to enter CS), it sleeps
    • when conditinal variable signals queuing process, it wakups
  • Protect a critical section:
    • Internal variables only accessible by code within the procedure
    • Only one process may be active within themonitor at a time
monitor monitor-name {
    // shared variable declarations
    procedure P1 (...) { ... }
    procedure P2 (...) { ... }
	...
    procedure Pn (...) { ... }
    initialization code (...) { ... }
}
  • Operations: includes operations processes might want to run
  • Intialization code: set the intial value for shared data
  • Conditional variables
    • example: there are 2 queues for each shared variable (conditional variables)
    • better than 1 as x only need to signal the producer when empty and y signals consumer when full
    • x.wait(): a process that invokes the operation is suspended until x.signal()
    • x.signal(): resumes one of processes that invoked x.wait()
      • If no x.wait() on the variable, then it has no effect on the variable

two