![]() |
VOOZH | about |
Dekker’s Algorithm was the first correct solution to the critical section problem for two processes. It is significant in the history of operating systems because:
A process is generally represented as :
do {
//entry section
critical section
//exit section
remainder section
} while (TRUE);
The solution to the critical section problem must ensure the following three conditions:
Algorithm: It requires both an array of Boolean values and an integer variable:
var flag: array [0..1] of boolean;
turn: 0..1;
repeat
flag[i] := true;
while flag[j] do
if turn = j then
begin
flag[i] := false;
while turn = j do no-op;
flag[i] := true;
end;
critical section
turn := j;
flag[i] := false;
remainder section
until false;
Dekker’s Algorithm was developed in five versions, each improving upon the previous one. Let’s analyze them:
The idea is to use a common or shared thread number between processes and stop the other process from entering its critical section if the shared thread indicates the former one already running.
turn to decide whose turn it is.turn matches its ID.To remove lockstep synchronization, it uses two flags to indicate its current status and updates them accordingly at the entry and exit section.
To re-ensure mutual exclusion, it sets the flags before the entry section itself.
Uses small time interval to recheck the condition, eliminates deadlock, and ensures mutual exclusion as well.
Idea is to use favoured thread notion to determine entry to the critical section. Favoured thread alternates between the thread providing mutual exclusion and avoiding deadlock, indefinite postponement, or lockstep synchronization.
This version guarantees a complete solution to the critical solution problem.
| Version | Mechanism | Problem |
|---|---|---|
| 1. Turn variable only | Strict alternation | No progress if one process exits permanently |
| 2. Flags (after entry) | Mutual exclusion attempt | Both may enter → violation |
| 3. Flags (before entry) | Ensures mutual exclusion | Deadlock possible |
| 4. Flags + random backoff | Avoids deadlock | Starvation (indefinite postponement) |
| 5. Final Dekker’s Algorithm | Flags + turn variable | Correct solution (ensures all 3 requirements) |