01 /*
02 
03  Pour chacun des algorithmes suivants, déterminer s'il sont corrects.
04 
05  Prouver l'éventuelle correction par méthode Owicki-Gries
06 
07 */
08 
09 
10 public class Algorithme3 extends ExclusionMutuelle
11 {
12     public Algorithme3() {
13       flag[0false;
14       flag[1false;
15       turn = 0;
16     }
17 
18     public void Pmutex(int t) {
19       int other;
20       other = 1-t;
21       flag[ttrue;
22       turn = other;
23       while ((flag[other== true&& (turn == other))
24         Thread.yield();
25     }
26 
27     public void Vmutex(int t) {
28       flag[tfalse;
29     }
30 
31     private volatile int turn;
32     private volatile boolean[] flag = new boolean[2];
33 }
Java2html