shared: bool flag[] = { false, false }; // Do I want to be in the C.S. int turn = 0; // Whose turn is it Process 0 | Process 1 ---------------------------+-------------------------- flag[0] = true; | flag[1] = true; turn = 1; | turn = 0; while (flag[1] && | while (flag[0] && turn == 1) | turn == 0) pause(); | pause(); C.S. | C.S. flag[0] = false; | flag[1] = false; | (Peterson's algorithm)