July 2017
Intermediate to advanced
244 pages
6h 33m
English
Software-defined mutual exclusion implementations are all based on busy-waiting. An example is Dekker's algorithm, which defines a system in which two processes can synchronize, employing busy-wait to wait for the other process to leave the critical section.
The pseudocode for this algorithm is as follows:
variables wants_to_enter : array of 2 booleans turn : integer wants_to_enter[0] ← false wants_to_enter[1] ← false turn ← 0 // or 1
p0: wants_to_enter[0] ← true while wants_to_enter[1] { if turn ≠ 0 { wants_to_enter[0] ← false while turn ≠ 0 { // busy wait } wants_to_enter[0] ← true } } // critical section ... turn ← 1 wants_to_enter[0] ← false // remainder section
p1: wants_to_enter[1] ← true while wants_to_enter[0] { if turn ...Read now
Unlock full access