rec16 - Recitation 16 Concurrency: Condition Variables and...

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

View Full Document Right Arrow Icon
Recitation 16 Concurrency: Condition Variables and Message Passing Condition Module For this module we refer to OCaml's condition module documentation . The reader writer concurrency pattern (taken from lec16.ml ) (* Reader/writer; a classic conurrency pattern (concurrent readers and * one exclusive writer, CRXW). There is mutual exclusion between a * single writer and any of many readers, but readers can operate at * the same time (because they do not change any shared state). * * This is accomplished with a shared variable n which counts the * number of readers currently active. Each reader momentarily acquires * the mutex to increment the count, then does their work, then * momentarily acquires the mutex to decrement the count. * * The writer needs to wait until there are no readers. This is * achieved using a condition variable to signal when no are readers * active. The writer waits for the condition to be true. The readers * signal the condition if when they finish there are no readers * active. * * Such waiting on a condition before taking a mutex is known as a * semaphore. * * Condition.wait operates by simultaneously unlocking the specified * mutex and waiting (sleeping) for the specified condition to be * signalled by some other thread. Since the mutex is unlocked other * threads can do work, including using Condition.signal to signal the
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 10/25/2009 for the course PHYS 2214 at Cornell.

Page1 / 4

rec16 - Recitation 16 Concurrency: Condition Variables and...

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