Peterson locking primitive course code.
[TD_SE.git] / peterson / peterson.c
diff --git a/peterson/peterson.c b/peterson/peterson.c
new file mode 100644 (file)
index 0000000..f588503
--- /dev/null
@@ -0,0 +1,23 @@
+#define FALSE 0
+#define TRUE 1
+#define N 2                    // nombre de processus
+int turn;                      // à qui le tour?
+int flags[N];          // initialement valeurs FALSE
+
+/* attente active */
+
+static void enter_region(int process) {                                // entrée en SC
+       int other;
+       other = 1 - process;
+       flags[process] = TRUE;
+       turn = process;
+       while (turn == process && flags[other] == TRUE) ;
+}
+
+static void leave_region(int process) {                                // sortie de SC
+       flags[process] = FALSE;
+}
+
+int main() {
+
+}