|
|
Peterson's AlgorithmPeterson's algorithm is a concurrent programming algorithm for mutual exclusion that allows two processes to share a single-use resource without conflict, using only shared memory for communication. f0 := 0; f1 := 0; last := 0; p0: f0 := 1; p1: f1 := 1 last := 0; last := 1 REPEAT REPEAT UNTIL f1 = 0 OR last != 0; UNTIL f0 = 0 OR last != 1; { critical section } { critical section } f0 := 0; f1 := 0; See also Dekker's algorithm
|
 |