Systemos fair access to resources parallel computing

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: higher-level synchronization construct Ensure a group of cooperating threads reach a common synchronization synchronization point Many uses …. system/OS – fair access to resources parallel computing Basic Barrier Basic Barrier – 2 threads blue = new semaphore (“my_S”, 0); (“ 0) purple = new semaphore (“my_S”, 0); void BarrierCompute() { while(not done) { Compute(); purple->V(); blue->P(); } } void BarrierCompute() { while(not done) { Compute(); blue->V(); purple->P(); } } New New Construct Implement a synchronization construct called an EventBarrier Operations: () EB.wait () : blocks the caller until an EB.signal() is done, if EB.signal() () has already been done then don’t block EB EB.signal():put EB in signalled state for time T and wakeup anyone that is blocked (if any) EB.complete(): blocks the caller until everyone that issued a prior EB.wait has executed the EB.Complete ti signaller … …. wait for an important event(EB.wait) signal event has happened (EB.signal) … make sure everyone else has reached this point (EB.complete) Exercise Exercise to Ponder (cont’d) class EventBarrier { int int n=0, num; // expect num threads, n completed num; // expect num threads, completed lock mutex_w, mutex_c; boolean signalled = FALSE; Condition CVw, CVc; CV CV void signal () { mutex_w.acquire (); signalled = TRUE; CVw.broadcast (&mutex_w); mutex_w.release (); …. Wait for time T, turn off signal } EventBarrier EventBarrier Example: Message Channel repeatedly send data message channel Behavior: 1. Output thread never blocks if the channel is already open. 2. 2. Channel never closes while a thread is sending data. (“correctness”) 3. Once a thread sends, it waits until all others have sent before sending again (“fair use”) EventBarrier EventBarrier Example EventBarrier channel; void OutputThread { while (TRUE) { ComputeDataToSend(); channel.Wait(); SendData(); channel.Complete();} } void ChannelScheduler() { while (TRUE) { WaitUntilTimeToOpenChannel(); /* open floodgate for burst of outgoing data */ channel.Signal(); /* channel is closed */ } } The The Roots of Condition Variables: Monitors A monitor is a “magic” module (a collection of procedures and state) with serialized execution and integrated wait/signal primitives. CVs are easier to understand if we think about them in terms of the original monitor formulation. state P1() ready At most one thread may be active in a given monitor at any time. (enter) P2() to enter P3() signal() (exit) A thread...
View Full Document

This document was uploaded on 04/02/2014.

Ask a homework question - tutors are online