Lec09 - Computer Science Lecture 9 page 1 Computer Science...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Computer Science Lecture 9, page 1 Computer Science CS377: Operating Systems Last Class: Semaphores • A semaphore S supports two atomic operations: – S ! Wait(): get a semaphore, wait if busy semaphore S is available. – S ! Signal(): release the semaphore, wake up a process if one is waiting for S. • Binary or Mutex Semaphore: grants mutual exclusive access to a resource • Counting Semaphore: useful for granting mutually exclusive access for a set of resources • Semaphores are useful for mutual exclusion, progress and bounded waiting Computer Science Lecture 9, page 2 Computer Science CS377: Operating Systems Today: Monitors and Condition Variables • What is wrong with semaphores? • Monitors – What are they? – How do we implement monitors? – Two types of monitors: Mesa and Hoare • Compare semaphore and monitors Computer Science Lecture 9, page 3 Computer Science CS377: Operating Systems What's wrong with Semaphores? • Semaphores are a huge step up from the equivalent load/store implementation, but have the following drawbacks. – They are essentially shared global variables. – There is no linguistic connection between the semaphore and the data to which the semaphore controls access. – Access to semaphores can come from anywhere in a program. – They serve two purposes, mutual exclusion and scheduling constraints. – There is no control or guarantee of proper usage. • Solution: use a higher level primitive called monitors Computer Science Lecture 9, page 4 Computer Science CS377: Operating Systems What is a Monitor? • A monitor is similar to a class that ties the data, operations, and in particular, the synchronization operations all together, • Unlike classes, – monitors guarantee mutual exclusion, i.e., only one thread may execute a given monitor method at a time. – monitors require all data to be private. Computer Science Lecture 9, page 5 Computer Science CS377: Operating Systems Monitors: A Formal Defnition • A Monitor defines a lock and zero or more condition variables for managing concurrent access to shared data. – The monitor uses the lock to insure that only a single thread is active in the monitor at any instance. – The lock also provides mutual exclusion for shared data. – Condition variables enable threads to go to sleep inside of critical sections, by releasing their lock at the same time it puts the thread to sleep. • Monitor operations: – Encapsulates the shared data you want to protect. – Acquires the mutex at the start. – Operates on the shared data. – Temporarily releases the mutex if it can't complete....
View Full Document

This note was uploaded on 09/30/2010 for the course CS 377 taught by Professor Corner during the Fall '08 term at UMass (Amherst).

Page1 / 10

Lec09 - Computer Science Lecture 9 page 1 Computer Science...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online