01.06.2014 Views

Concurrent Systems II - Bad Request - Trinity College Dublin

Concurrent Systems II - Bad Request - Trinity College Dublin

Concurrent Systems II - Bad Request - Trinity College Dublin

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Attempt #5, derived from #4<br />

Critical Section Problem Attempt #5<br />

boolean wantp ← false, wantq ← false, turn ← 1<br />

p<br />

q<br />

loop forever<br />

loop forever<br />

p1: non-critical section q1: non-critical section<br />

p2: wantp ← true q2: wantq ← true<br />

p3: while wantq q3: while wantp<br />

if turn = 2 if turn = 1<br />

p4: wantp ← false q4: wantq ← false<br />

await turn = 1 await turn = 2<br />

p5: wantp ← true q5: wantq ← true<br />

p6: critical section q6: critical section<br />

turn ← 2 turn ← 1<br />

p7: wantp ← false q7: wantq ← false<br />

121<br />

<strong>Trinity</strong> <strong>College</strong> <strong>Dublin</strong><br />

© Mike Brady 2007–2009

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

Saved successfully!

Ooh no, something went wrong!