{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec8 - CS 372 Operating Systems Mike Dahlin Lecture#8...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
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
Image of page 2
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 .... General problem e.g., wait for other thread to finish, wait for other thread to produce work, wait for other thread to consume work, wait for other thread to accept a connection, wait for other thread to get bytes off disk, How do we do it? Need new synchronization primitive "Wait until X" 4. Definition of Semaphores like a generalized lock first defined by Dijkstra in late 60’s originally main synchronization primitive in Unix (now others available) semaphore has a no n - negative integer value and supports the following two operations: semaphore - >P() an atomic operation that waits for the semaphore to
Image of page 3

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

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern