In Dekkers algorithm written for an arbitrary number of proc

In Dekker\'s algorithm, written for an arbitrary number of processes by changing the statement executed when leaving the critical section from turn = 1 - i //i.e. P0 sets turn to 1 and P1 sets turn to 0 to turn = (turn + 1) % n //n = number of processes Evaluate the algorithm when the number of concurrently executing processes is greater than two. If the changes create any problems, give an example of executing sequence.

Solution

If two processes attempt to enter a critical section at the same time, the algorithm will allow only one process in, based on whose turn it is. If one process is already in the critical section, the other process will busy wait for the first process to exit. This is done by the use of two flags, wants_to_enter[0] and wants_to_enter[1], which indicate an intention to enter the critical section on the part of processes 0 and 1, respectively, and a variable turn that indicates who has priority between the two processes.

Dekker\'s algorithm can be expressed in pseudocode, as follows

variables
wants_to_enter : array of 2 booleans
turn : integer

wants_to_enter[0] <- false
wants_to_enter[1] <- false
turn <- 0 // or 1
p0:
wants_to_enter[0] <- true
while wants_to_enter[1] {
if turn <- 0 {
wants_to_enter[0] <- false
while turn <- 0 {
// busy wait
}
wants_to_enter[0] <- true
}
}

// critical section
...
turn <- 1
wants_to_enter[0] <- false
// remainder section
p1:
wants_to_enter[1] <- true
while wants_to_enter[0] {
if turn <- 1 {
wants_to_enter[1] <- false
while turn <- 1 {
// busy wait
}
wants_to_enter[1] <- true
}
}

// critical section
...
turn <- 0
wants_to_enter[1] <- false
// remainder section

In Dekker\'s algorithm, written for an arbitrary number of processes by changing the statement executed when leaving the critical section from turn = 1 - i //i.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site