lecture7 - Synchronization Without Busy Waiting The...

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

View Full Document Right Arrow Icon
Synchronization Without Busy Waiting The solutions we’ve considered up to now, Dekker’ sand Peterson’ salgorithms and hardware test- and-set all share an unpleasent attribute. processes waiting to enter the critical section use the CPU to keep checking if theycan enter their critical section. The act of using the CPU to repeatedly check for entry to the critical section is called busy waiting. Processes that are busy waiting use their whole quantum doing nothing (if they’re waiting, the process actually in its critical section can’ tbeadvancing. ..). In general this isn’tgood. 1 Not only can busy waiting be inconvenient, on systems with a priority scheduler priority inversions can occur .(Waiting for entry to a critical section is a prime cause of these). To avoid busy waiting, we’ll create resources that enforce mutual exclusion and makethem accessi- ble by through the operating system. Processes waiting to enter a critical section will be put in the blocked state, just liketheywere waiting for I/O, so that other processes can continue doing useful work. Semaphores Semaphores are shared counters with blocking semantics. Specifically ,Asemaphore is a non-neg- ative integer on which 2 operations are defined: P() or down() decrements the semaphore by one. 2 If the semaphore is zero, the process calling P() is blocked until the semaphore is positive again. V() or up() increments the semaphore by one. P() and V() are atomic .A process sees all or none of a P() or V(), and no P() or V() is eve rlost. These operations are generally invokedbyprocesses using system calls, and within the kernel, the simple operations of incrementing and decrementing are done with interrupts offtomakethem atomic. Blocking is accomplished by putting the process on a blocked queue associated with each semaphore. The nachos implementation of semaphores is a good one to look at for the flavorofit. The Bounded Buffer Problem Using Semaphores Acommon situation in operating systems is to have a bounded buffer shared by 2 processes. One (the producer) puts data into the buffer and the other (the consumer) removesit. The buffer has a finite size, so the producer has to wait when it’ sfull, and the consumer has to wait when it’
Background image of page 1

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

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

This note was uploaded on 02/28/2008 for the course CS 402 taught by Professor Tedfaber during the Spring '05 term at USC.

Page1 / 7

lecture7 - Synchronization Without Busy Waiting The...

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

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