TURN VARIABLE




Software mechanism implemented at user mode-only for two processes. It is a lock shared by two processes.

Analysis of Turn Variable approach:


Mutual Exclusion:
The strict alternation approach provides mutual exclusion in every case. This procedure works only for two processes. The pseudo code is different for both of the processes. The process will only enter when it sees that the turn variable is equal to its Process ID otherwise not Hence No process can enter in the critical section regardless of its turn.
Progress:
Progress is not guaranteed in this mechanism. If P0 doesn't want to get enter into the critical section on its turn then P1 got blocked for infinite time. P1 has to wait for so long for its turn since the turn variable will remain 0 until P0 assigns it to 1.
Portability
The solution provides portability. It is a pure software mechanism implemented at user mode and doesn't need any special instruction from the Operating System.

Demo

Steps

Lights

Input

Initially there will be already 2 process in the initial state.

For processing a process click on the respective process button and the process will be added to the respective state.

Output

The output will be according to the user input on the respective process for different states and according to the turn state.

Turn variable is shown above added state.

Lights