Peculiarity of Peterson’s Solution to Process Synchronization
void enter_region(int process) { int other = 1 – process; turn Initial State interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn interested 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } FALSE while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; other 1 Process 0 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } TRUE TRUE while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn 1 interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } TRUE TRUE So, wait… while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1
void enter_region(int process) { int other = 1 – process; Process 1 turn 1 But process 1 was supposed to enter its critical region… interested 1 1 void enter_region(int process) { int other = 1 – process; interested[process] = TRUE; turn = process; while (turn==process && interested[other]==TRUE){} } void leave_region(int process) { interested[process] = FALSE } while (TRUE) { enter_region(0); critical_region(); leave_region(0); } while (TRUE) { enter_region(1); critical_region(); leave_region(1); } Process 0 Process 1