03.05.2013 Views

Concurrency en race condities

Concurrency en race condities

Concurrency en race condities

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

monitor ReadersAndWriters {<br />

static int Readers = 0;<br />

static int SomeoneIsWriting = 0;<br />

static condition ReadingAllowed,<br />

WritingAllowed;<br />

startRead () {<br />

if (SomeoneIsWriting ||<br />

Readers++;<br />

Readers/writers monitor<br />

queue(WritingAllowed))<br />

wait(ReadingAllowed);<br />

signal(ReadingAllowed);<br />

}<br />

<strong>en</strong>dRead () {<br />

Readers--;<br />

if (Readers == 0)<br />

signal(WritingAllowed);<br />

}<br />

}<br />

startWrite () {<br />

}<br />

if ((Readers > 0) ||<br />

<strong>en</strong>dWrite () {<br />

}<br />

SomeoneIsWriting)<br />

wait(WritingAllowed);<br />

SomeoneIsWriting = 1;<br />

SomeoneIsWriting = 0;<br />

if (queue(ReadingAllowed))<br />

signal(ReadingAllowed);<br />

else<br />

signal(WritingAllowed);<br />

College OS 2010 – 2011 44

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!