Download presentation
Presentation is loading. Please wait.
Published byLiana Makmur Modified over 6 years ago
1
Peculiarity of Peterson’s Solution to Process Synchronization
2
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
3
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
4
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
5
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
6
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
7
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
8
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
9
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
10
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
11
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
12
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
13
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
14
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
15
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
16
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
17
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
18
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
19
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.