-
6
pages
-
Français
-
Documents
Description
. .Readers and Writers (1/6)Concurrency 2A shared resource is concurrently read or modified.From shared memory• Several processes may concurrently read the shared resource.to synchronization• A single process (the writer) may modify the resource.• When readers are running, no writer can be executed.by communication on• When a writer is running, no other writer, nor a reader can runchannelsconcurrently.PROCEDURE Read() = PROCEDURE Write() =Jean-Jacques L´evy (INRIA - Rocq)BEGIN BEGINAcquireShared(); AcquireExclusive();MPRI concurrency course with :(∗ read shared data ∗) (∗ write shared data ∗)ReleaseShared(); ReleaseExclusive();Pierre-Louis Curien (PPS)END Read; END Write;Eric Goubault (CEA)James Leifer (INRIA - Rocq)Catuscia Palamidessi (INRIA - Futurs)1 3. .Les lecteurs et les ´ecrivains (2/6)PlanEn lecture, on a nReaders simultan´es (nReaders > 0).• exercises (followup)En ´ecriture, on a nReaders =−1.• readers and writersPROCEDURE AcquireShared() = PROCEDURE AcquireExclusive() =BEGIN BEGIN• the five philosophersLOCK m DO LOCK m DOWHILE nReaders = −1 DO WHILE nReaders != 0 DO• synchronous communication channelsThread.Wait(m, c); Thread.Wait(m, c);• CML END; END;++ nReaders; nReaders := −1;• coding semaphoresEND; END;END AcquireShared;END AcquireExclusive;PROCEDURE ReleaseShared() = PROCEDURE ReleaseExclusive() =BEGIN BEGINLOCK m DO LOCK m DO−− nReaders;nReaders := 0;IF nReaders = 0 THENThread.Broadcast(c);END;Thread ...
-
Publié par
-
Langue
Français