peterson’s algorithm
Registers: Turn = 0 Want0 = 0 Want1 = 0
Process A
Want0 = 1;
Turn = 1;
while(Want1 && Turn == 1) {
critical_section();
}
Want0 = 0;
Process B
Want1 = 1;
Turn = 0;
while(Want0 && Turn == 1) {
critical_section();
}
Want1 = 0;
Disadvantage
The waiting process repeatedly tests the while-loop condition, rather than going into blocked state.
Low level implementation
- Error-prone
- Mutual exclusion needs to be simplified
Too specific to 2 processes.