# Lec05-readerwriterx4 - Goals for Today CS162 Operating Systems and Systems Programming Lecture 5 Semaphores Conditional Variables February 1 2012

This preview shows pages 1–3. Sign up to view the full content.

Page 1 CS162 Operating Systems and Systems Programming Lecture 5 Semaphores, Conditional Variables February 1, 2012 Anthony D. Joseph and Ion Stoica http://inst.eecs.berkeley.edu/~cs162 Lec 5.2 2/1/12 Anthony D. Joseph and Ion Stoica CS162 ©UCB Spring 2012 Goals for Today • Continue with Synchronization Abstractions – Semaphores, Monitors and condition variables • Readers-Writers problem and solution Note: Some slides and/or pictures in the following are adapted from slides ©2005 Silberschatz, Galvin, and Gagne. Many slides generated from lecture notes by Kubiatowicz. Lec 5.3 2/1/12 Anthony D. Joseph and Ion Stoica CS162 ©UCB Spring 2012 Where are we going with synchronization? • We are going to implement various higher-level synchronization primitives using atomic operations – Everything is pretty painful if only atomic primitives are load and store – Need to provide primitives useful at user-level Load/Store Disable Ints Test&Set Comp&Swap Locks Semaphores Monitors Send/Receive Shared Programs Hardware Higher- level API Programs Lec 5.6 2/1/12 Anthony D. Joseph and Ion Stoica CS162 ©UCB Spring 2012 Semaphores • Semaphores are a kind of generalized locks – First de±ned by Dijkstra in late 60s – Main synchronization primitive used in original UNIX • De±nition: a Semaphore has a non-negative integer value and supports the following two operations: – P(): an atomic operation that waits for semaphore to become positive, then decrements it by 1 » Think of this as the wait() operation – V(): an atomic operation that increments the semaphore by 1, waking up a waiting P, if any » This of this as the signal() operation – Note that P() stands for “ proberen” (to test) and V() stands for verhogen” (to increment) in Dutch

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

View Full Document