Peterson's algorithm
Peterson'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.
The following is wikicode, a proposed pseudocode for use in many articles.
f0 := 0
f1 := 0
last := 0
p0: f0 := 1 p1: f1 := 1
last := 0 last := 1
do { do {
} until f1 = 0 or last ≠ 0 } until f0 = 0 or last ≠ 1
// critical section // critical section
f0 := 0 f1 := 0
See also
Categories: Computer stubs