+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

Wei-Lun Hungadd chap. 2 and 3df69975

master
503 B19 linesraw
1class Dekker implements Lock {
2    boolean wantCS[] = {false, false};
3    int turn = 1;
4    public void requestCS(int i) { // entry protocol
5        int j = 1 - i;
6        wantCS[i] = true;
7        while (wantCS[j]) {
8            if (turn == j) {
9                wantCS[i] = false;
10                while (turn == j) ;// busy wait
11                wantCS[i] = true;
12            }
13        }
14    }
15    public void releaseCS(int i) { // exit protocol
16        turn = 1 - i;
17        wantCS[i] = false;
18    }
19}