Professional Documents
Culture Documents
Steve Smokowski
Lester Wolfgang
History
Created by a Dutch mathematician T.J
Dekker
Published in 1965
First correct solution for the two-process
case (Mutual Exclusion)
Peterson Simplified Dekker’s Algorithm,
You will see a great deal of similarity
between the two
Concepts of Dekker’s Algorithm
Two Variables
– Favored Process Variable and Interested Flag
Variable
First we set our interested flag then check
the other processes flag
If that flag is also set, we evaluate the
favored variable
Continued....
If the turn is ours we wait for the flag of
the other process to clear
If the turn belongs to the other process
we wait, but we clear our flag before
waiting to avoid blocking
when the turn is given to us we reset our
flag and proceed
Algorithm
INITIALIZATION:
– int shared favored_process=i
– int shared interested[2]
– Upon initialization we initialize the interested
flag for the two processes and the favored
process flag
Algorithm
ENTRY PROTOCOL (for Process i ):
void enter_region(int process)
{
int other = 1-process;
interested[process] = TRUE;
while ( interested[other] )
{
if ( favored_process == other )
{
interested[process] = FALSE;
while ( favored_process == other );
interested[process] = TRUE;
}
}
}
Algorithm
Upon Exiting the Critical Section the
other process is set to favored and our
interested flag is set to false, Below is
the Code
EXIT PROTOCOL (for Process i ):
/* pass the turn on, and release the resource */
void leave_region(int process)
{
int other = 1 - process;
favored_process = other;
interested[process] = FALSE;
}
Analysis of Condition 1
Notwo processes simultaneously in critical
region
– Dekker’s Algorithm handles this through the
use of the two variables
– In order to enter the CS you must set your
own interested flag. Every process then
checks the other flag after setting its own
flag. If both are set to wanting to enter the
favored variable is evaluated and only one
process enters the CS.
Analysis of Condition 2
No
assumptions made about speeds or
numbers of CPUs
– Dekker’s Algorithm makes no assumptions
about hardware of any kind. It is a pure
software solution to mutual exclusion
Analysis of Condition 3
No process running outside its critical
region may block another process
– No process in this algorithm can block
another process, they simply take turns,
which ensures this condition is met
Analysis of Condition 4
No process must wait forever to enter its
critical region
– Deadlock within the algorithm is not possible
– No process waits with its flag constantly set,
and only process has the turn
– The process with the turn will eventually
discover the other flag free and will proceed
Race Condition
Dekker solves this by adding the concept
of a favored process
When both processes arrive to enter the
CS at roughly the same time, one process
is favored and enters the CS, the priority
reverses upon that process leaving the CS
and the other Process becomes the
favored process
Sample Trace
Process 1 Calls Enter Region
Set other
other=0
=
Set0 our interested flag
interested[1]=true
to trueother processes
While
while(interested[0])
if(favored_process==other) interested flag equals
interested[process] = false true enter while, else
If other
enter CSprocess is
while(favored_process==other);
favored, set our
intersted[1]=true
interested flag to false
Once other process
and busy wait
leaves CS it will set
our process to
favored process
and the while will
break, and we set
Problems
Not a Fair Solution
Fair=After a process makes a request to
enter its CS, there must be a limit on the
number of times the other processes are
allowed to enter their CS's, before that
request is granted
With multiple processes Dekker’s
Algorithm is not a fair one
Questions