FOR FREE MATERIALS

Strict mechanism or Turn variable or Decker’s algorithm with special variable

 

This new mechanism is used to solve the progress problem of turn variables. To solve this problem here using a special variable to see which process wants to enter into its critical section.

 

want_to_enter - variable

want_to_enter[ 0 ] = T   -  For process P0

want_to_enter[ 1 ]= T   -  For process P1

 

Initially                        

want_to_enter[0] = F              

want_to_enter[1] = F                                                  

 

Now at step 1, want_to_enter[0] = T and want_to_enter[1] = F, so, P0 enter into its critical section.

At step 2, want_to_enter[0] = F and want_to_enter[1] = T,  so, P1 enter into its critical section and P0 exit.

 

             

# From the above code, we come to know that when want_to_enter[0] is true and want_to_enter[1] is false then, process P0 enter into the critical section.

 

# When want_to_enter[1] is true and want_to_enter[0] is false then, process P1 enter into critical section.

 

# But only when both variable values are the same true/false for process P0 and P1, then it has some problem.

 

# Progress is there i.e. here process which is not interested to go into critical section, never stop another process which wants to go into its critical section.

 

Now after assigning the special variable to the Strict mechanism or Decker’s algorithm

1)  Mutual Exclusion - Yes

2)  Progress - Yes 

3)  Bounded wait - No

4)  Portable - Yes

 

After introducing the special variable want_to_enter to the strict mechanism, may lead to deadlock sometimes.

And as we know once deadlock occurs, bounded waiting is not possible.

 

 

Example of Deadlock

 

In the above code, we assume that the P0 and P1 functions can call more than one time. 

Initially want_to_enter[0] = F and want_to_enter[1] = F 

 

Step 1: P0 first calls its function, assign want_to_enter[0]=T then go into its critical section and preempted. 

 

 

Step 2: Now P1 runs and assign want_to_enter[1] = T, but does not go into the critical section because the critical section is busy with P0. So, P1 is waiting at this moment.

 

 

Step 3: Now P0 is in ready state and executes the rest of the line of code i.e. want_to_enter[0] = F, then terminated. 

 

 

Step 4: Immediately P0 call the function again and run instructions, assign want_to_enter[0] = T, but now it does not go into critical section because want_to_enter[1] = T (see step 2). So, P0 is waiting at this moment.

 

 

Now P1 is waiting until it gets the critical section, and P0 is waiting, it does not go into its critical section because want_to_enter[1] = Tthe loop is not satisfied for critical section entry.

 

So, both are waiting forever and it becomes a deadlock.

 

From the above example, it is clear that bounded waiting is not satisfied here.