lec8 - CS 372: Operating Systems Mike Dahlin 1 02/08/11...

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: CS 372: Operating Systems Mike Dahlin 1 02/08/11 Lecture #8: Semaphores Shared objects, Monitors, Condition Variables, and Bounded buffer ********************************* Review -- 1 min ********************************* Hardware support for synchronization Building higher-level synchronization programming abstractions on top of hardware support (e.g., Lock) ********************************* Outline - 1 min ***************************** ***** Definition of semaphore Example of programming w. semaphore Semaphore expresses 2 types of synchronizatio n mutex (like lock) synchronization (wait for some event) Simple implementation (time permitting) Two kinds of synchronization Monitor = lock + c.v. + shared state = shared object Simple implementation ********************************* Preview - 1 min ********************************* How to program with shared objects ********************************* Lecture - 32 min ********************************* 1. Motivation writing concurrent programs hard coordinate updates to shared memory CS 372: Operating Systems Mike Dahlin 2 02/08/11 synchronization coordinating multiple concurrent activities that are using shared state Question: what are the right synchronization abstractions to make it easy to build concurrent programs? Answer will necessarily be a compromise : between making it easy to modify shared variables any time you want and controlling when you can modify shared variables. between really flexible primitives that can be used in a lot of different ways and simple primitives that can only be used one way (but are more difficult to misuse) Rules will seem a bit strange why one definition and not another? no absolute answer history has shown that they are reasonably good if you follow these definitions, you will find writing correct code easier. for now just take them as a given; use it for a while; then, if you can come up with something better, be my guest! 2. Shared object abstraction [[PICTURE -- shared state, methods operating on shared state -- example -- bounded buffer/producer consumer queue -- methods: add(), remove() -- state: linked list (or array or ...), fullCount, ... -- Accessed by several threads --> must synchronize access]] 3. 2 types of synchronization Convenient to break synchronization into two cases (1) Mutual exclusion only allow one thread to access a given set of shared state at a time E.g., bounded buffer How do we do it? Each shared object has lock and shared state variables CS 372: Operating Systems Mike Dahlin 3 02/08/11 Public methods acquire the lock before reading/writing member state variables (2) Scheduling constraints wait for some other thread to do something E.g., bounded buffer.......
View Full Document

This note was uploaded on 01/18/2012 for the course INFORMATIK 2011 taught by Professor Phanthuongcang during the Winter '11 term at Cornell University (Engineering School).

Page1 / 18

lec8 - CS 372: Operating Systems Mike Dahlin 1 02/08/11...

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