Systemos fair access to resources parallel computing

Info icon This 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

{[ 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