Dekker’s Algorithm for Mutual Exclusion

Dekker’s Algorithm:

Dekker’s Algorithm was developed by the Dutch mathematician Dekker. It was developed for the mutual exclusion of two processes. In just a few lines of code. Dekker’s algorithm efficiently handles two processes of mutual exclusion without the need for any special hardware instructions.

Algorithm:


var favored process:(first,second);
p1 wants_to_enter, p2 wants_to_enter : Boolean;
procedure processone;
begin
while true do
begin
p1 wants_to_enter:=true;
while p2 wants_to_enter do
if favoured process=second then
begin
p1 wants_to_enter=false;
while favoured process=second do;
p1 wants_to_enter=true;
end;
critical section one;
favoured process=second;
p1 wants_to_enter=false;
otherwise one;
end;
procedure process two;
begin
while true do
begin
p2 wants_to_enter=true;
while p1 wants_to_enter do
if favoured process=first then
begin
p2 wants_to_enter=false;
while favoured process=first do;
p2 wants_to_enter=true;
end;
critical section two
favoured process=first;
p2 wants_to_enter=false;
otherwise two;
end;
begin
p1 wants_to_enter=false;
p2 wants_to_enter=false;
favoured process=first;
perbegin
process one;
process two;
parend
end;