Peterson locking primitive course code.
[TD_SE.git] / peterson / peterson.c
1 #define FALSE 0
2 #define TRUE 1
3 #define N 2 // nombre de processus
4 int turn; // à qui le tour?
5 int flags[N]; // initialement valeurs FALSE
6
7 /* attente active */
8
9 static void enter_region(int process) { // entrée en SC
10 int other;
11 other = 1 - process;
12 flags[process] = TRUE;
13 turn = process;
14 while (turn == process && flags[other] == TRUE) ;
15 }
16
17 static void leave_region(int process) { // sortie de SC
18 flags[process] = FALSE;
19 }
20
21 int main() {
22
23 }