01 /*
02 Exclusion Mutuelle :
03
04 Algorithme d'Hyman (1966)
05 */
06 public class Hyman extends ExclusionMutuelle
07 {
08 public Hyman() {
09 flag[0] = false;
10 flag[1] = false;
11 turn = 0;
12 }
13
14 public void Pmutex(int t) {
15 int other = 1-t;
16 flag[t]= true;
17
18 while (turn==other) {
19 while (flag[other])
20 Thread.yield();
21 turn = t;
22 }
23 }
24 }
25 public void Vmutex(int t) {
26 flag[t] = false;
27 }
28
29 private volatile int turn;
30 private volatile boolean[] flag = new boolean[2];
31 }
|