



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




page 1
©Bruce Char and Vera Zaychik. All rights reserved by the author. Permission is given to students enrolled in CS361 Fall 2004 to reproduce these notes for their own use.
page 2
page 3
page 4
page 7
page 8
page 9
–What’s wrong with this? page 10
public void WanttoEnterCS(int i) { while (turn!=i) Thread.currentThread().yield(); // go from running back to run queue give someone else a // chance. }
public void finishedInCS(int i) { turn = other(i); // this sets I to something other than i }
page 19
page 20
page 21
page 22
page 23
public void wantToEnterCS(int I) { desireCS[I].value = true; while (desireCS[other(I)] .value) { desireCS[i].value = false; // back off Thread.currentThread().yield(); desireCS[i].value = true; }
public void finishedInCS(int I) { desireCS[I].value = false; // unset flag } (^) page 24
page 25
public void wantToEnterCS(int I) { // preprotocol desireCS[I].value = true; while (desireCS[other(I)].value) { if (turn !=I) { // take turns backing off. desireCS[I].value = false; // back off while (turn !=I) // busy wait Thread.currentThread().yield(); desireCS[I].value=true; } // end if } // end while }
public void finishedInCS(int I) { // postprotocol desireCS[I].value = false; turn = other(I); } page 26
page 27
public void wantToEnterCS(int I) { // preprotocol desireCS[I].value = true; last = other(I); while (desireCS[other(I)].value && last == other(I)) // busy wait Thread.currentThread().yield(); }
public void finishedInCS(int I) { // postprotocol desireCS[I].value=false; }