3

William Stallings discuss various step by step process in developing Dekker's algorithm in his Operating Systems book. In process, he reaches to following version of algorithm (which is incomplete as it results in livelock):

1    
2    /*    PROCESS 0    */
3    . 
4    . 
5    flag[0] = true;
6    while (flag[1])
7    {
8       flag[0] = false;
9       /* delay */ ;            
10       flag[0] = true;
11    }
12    /* critical section*/; 
13    flag[0] = false;.
14    
15    .
16    
17    /*    PROCESS 1   */
18    . 
19    . 
20    flag[1] = true;
21    while (flag[0]) 
22    {
23       flag[1] = false;
24       /* do */ ; 
25       flag[1] = true;
26    }
27    /* critical section*/; 
28    flag[1] = false;.
29    
30    .
31    
32    

I want to know whether above algorithm satisfies the "bounded waiting" requirement of critical section solution.

My current opinion is that, if process 0 fails on lines 6,7,8,11,12,13,14,15, that is all lines where flag[0] is already set to true, then process 1 will be blocked and hence will result in unbounded waiting. Am I correct?

Also is there easy way to find whether given/proposed algorithm for critical section problem solution satisfies "bounded waiting" requirement?

Raphael
  • 73,212
  • 30
  • 182
  • 400
Mahesha999
  • 1,773
  • 7
  • 30
  • 45

2 Answers2

3

A reasonable definition of bounded waiting is:

After a process made a request to enter its critical section and before it is granted the permission to enter, there exists a bound on the number of turns that other processes are allowed to enter. [1]

In your case each process makes its request to enter by setting its flag (line 5 for Process 0, line 20 for Process 1. The granting of permission is the test of the other process' flag (flag[1] false on line 6 grants permission to Process 0, flag[0] false on line 21 grants permission to Process 1).

So the only way to test the bounded waiting requirement here is to consider the case that Process 0 has just tested flag[1] on line 6, and found it true, and ask, "how many times can Process 1 leave and reenter the critical section while Process 0 is stuck in the loop?" (Hint: consider the case where Process 0 has really bad luck, and Process 1 is able to leave and reenter the critical section during Process 0's delay on line 9).

[1] source: http://www.csl.mtu.edu/cs3331.ck/common/05-Sync-Basics.pdf

Wandering Logic
  • 17,863
  • 1
  • 46
  • 87
0

Dekker's algorithm operates in strict alternation format i.e. 2 processes will alternatively gain Critical section.

As the definition given above by Wandering Logic, there is only one process for which another process has to wait.For example if process P1 wants to enter critical section then at most it has to wait for only one process(i.e. P0) for gaining control of CS.

This shows that Dekker's algorithm ensures bounded waiting property.

Maharaj
  • 274
  • 3
  • 18