FOR FREE YEAR SOLVED

Strict mechanism or Turn Variable or Decker’s algorithm

 

In the case of the lock variable, we see the lock variable is working just as a simple tag.

 

But here we introduce a new mechanism: Strict mechanism or Decker’s algorithm or sometimes called turn variable which is exactly working as lock variable. 

 

It has two properties:

  • # Busy waiting solution.
  • # 2-process solution (P0, P1) or (Pi, Pj) i.e. It allows two processes and threads to share a single resource.

Here we mentioned two processes P0 and P1.

 

 

From the above code, 

it is clear that the condition for two processes to enter in its critical section is opposite to each other i.e. P0 enter when turn = 0 and P1 enter when turn = 1. 

The reason behind this mechanism is not two processes enter its critical section at a time.

So, It is satisfied Mutual Exclusion

 

Check for Progress:

Initially Turn=0.

 

#  If we consider the above code, process P0 satisfies the while loop condition i.e. Turn = 0, and then preempted.

 

# Now process  P1 is ready and willing to enter into its critical section but Turn = 0 means the critical section is locked for P1

 

# So, right now P0 has the key but it does not want to go into its critical section, even P1 is willing to enter into the critical section but P0 locked it.

 

 

From the above description, it is clear that Progress not is possible in the case of Decker’s algorithm or turn variable.

 

This mechanism satisfying:

1)  Mutual Exclusion - Yes

2)  Progress- No

3)  Bounded wait - Yes because here no two processes wait a long time.

4)  Portable - Yes

 

So, the only main problem is progress which is not possible for this mechanism.

 

Disadvantage of Strict mechanism or Turn variable or Decker’s algorithm: 

When process P0 leaves the critical region, it sets turn to 1, to allow process P1 to enter into its critical region. 

 

Suppose that process P1 finishes its critical region quickly, so that both processes are in their noncritical regions, with turn set to 0. 

 

Now, process P0 executes its whole loop quickly, exiting its critical region and setting turn to 1. At this point, turn is 1 and both processes are executing in their non-critical regions.

 

Suddenly, process P0 finishes its noncritical region and goes back to the top of its loop. Unfortunately, it is not permitted to enter its critical region now, because turn is 1 

 

But process P1 is busy with its noncritical region. 

 

So, P0 hangs in its while loop until process P1 sets turn to 0. 

 

Put differently, taking turns is not a good idea when one of the processes is much slower than the other.