Docsity

Monitors Message Passing - Operating Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Monitors Message Passing - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Operating Systems

Lecture 13:

Monitors. Message Passing.

Readers/Writers.

Roadmap

  • Concurrency
  • Mutual Exclusion: Hardware Support
  • Semaphores
  • Monitors
  • Message Passing
  • Readers/Writers Problem

Main characteristics:

  1. Local variables are accessible only by the monitor’s procedures and not by any external procedure.
  2. A process enters the monitor by invoking one of its procedures.
  3. Only one process may be executing in the monitor at a time;

Structure of a Monitor

Synchronization

  • Synchronisation achieved by condition variables within a monitor - only accessible by the monitor.
  • Operation on condition variables:
    • Cwait(c): Suspend execution of the calling process on condition c
    • Csignal(c): Resume execution of some process blocked after a cwait on the same condition

Roadmap

  • Concurrency
  • Mutual Exclusion: Hardware Support
  • Semaphores
  • Monitors
  • Message Passing
  • Readers/Writers Problem

Message Passing

  • The actual function of message passing is normally provided in the form of a pair of primitives:
  • send (destination, message)
  • receive (source, message)

General Message Format

Blocking send,

Blocking receive

  • Both sender and receiver are blocked until message is delivered
  • Known as a rendezvous
  • Allows for tight synchronization between processes.

Non-blocking Send

  • More natural for many concurrent programming tasks.
  • Nonblocking send, blocking receive
    • Sender continues on
    • Receiver is blocked until the requested message arrives
  • Nonblocking send, nonblocking receive
    • Neither party is required to wait

Producer/Consumer with Messages

Summary

  • OS as:
    • Multiprogramming, multiprocessing, distributed processing
    • Fundamental theme: concurrency
  • Mutual exclusion:
    • Condition in which only one of a set of concurrent processes is able to access a given resource or perform a given function at any time
    • One approach involves the use of special-purpose machine instructions
  • Synchronization mechanisms:
    • Semaphores: signalling between processes
    • Monitors: programming language construct
    • Message passing
  • Classical Inter-Process Communication (IPC) problems:
    • Producer/consumer, Barbershop, Readers/Writers

Readers/Writers Problem

  • A data area is shared among many processes
    • Some processes only read the data area, some only write to the area
  • Conditions to satisfy:
    1. Multiple readers may read the file at once.
    2. Only one writer at a time may write
    3. If a writer is writing to the file, no reader may read it.
  • Version