CSC/ECE 506 Spring 2011/ch7 jp
Peterson's Algorithm
Peterson’s algorithm, also known as Peterson’s solution, is an algorithm that addresses the critical section problem by meeting the 3 criteria of the problem: mutual exclusion, progress, and bounded waiting.
int turn; // turn for execution int interested[2]; // the processors interested void enter_region(int process) { int otherProcess; otherProcess = 1 - process; interested[process]=1; turn = process; while(turn == process && interested[otherProcess] == 1) { // busy wait } } void leave_region(int process) { interested[process] = 0; }