Dekkers Algorithm PowerPoint PPT Presentation

presentation player overlay
1 / 15
About This Presentation
Transcript and Presenter's Notes

Title: Dekkers Algorithm


1
Dekkers Algorithm
  • Steve Smokowski
  • Lester Wolfgang

2
History
  • Created by a Dutch mathematician T.J Dekker
  • Published in 1965
  • First correct solution for the two-process case
    (Mutual Exclusion)
  • Peterson Simplified Dekkers Algorithm, You will
    see a great deal of similarity between the two

3
Concepts of Dekkers 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

4
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

5
Algorithm
  • INITIALIZATION
  • int shared favored_processi
  • int shared interested2
  • Upon initialization we initialize the interested
    flag for the two processes and the favored
    process flag

6
Algorithm
  • ENTRY PROTOCOL (for Process i )
  • void enter_region(int process)
  • int other 1-process
  • interestedprocess TRUE
  • while ( interestedother )
  • if ( favored_process other )
  • interestedprocess FALSE
  • while ( favored_process other )
  • interestedprocess TRUE

7
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
  • interestedprocess FALSE

8
Analysis of Condition 1
  • No two processes simultaneously in critical
    region
  • Dekkers 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.

9
Analysis of Condition 2
  • No assumptions made about speeds or numbers of
    CPUs
  • Dekkers Algorithm makes no assumptions about
    hardware of any kind. It is a pure software
    solution to mutual exclusion

10
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

11
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

12
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

13
Sample Trace
  • Process 1 Calls Enter Region
  • other0
  • interested1true
  • while(interested0) if(favored_processother)
  • interestedprocess false
  • while(favored_processother)
  • intersted1true


Set other 0
Set our interested flag to true
While other processes interested flag equals true
enter while, else enter CS
If other process is favored, set our interested
flag to false and busy wait
Once other process leaves CS it will set our
process to favored process and the while will
break, and we set our interested flag to true
14
Problems
  • Not a Fair Solution
  • FairAfter 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 Dekkers Algorithm is not
    a fair one

15
Questions
Write a Comment
User Comments (0)
About PowerShow.com