What is the Need for Turn Variable?
- The need for a turn variable arises due to the problem of the lock variable.
- In the lock variable approach, the process is able to enter into the critical section only when the lock variable is set to 1.
- In the lock variable approach, more than one process has a lock variable value of 1 at the same time.
- Due to such conditions, the lock variable is not able to guarantee mutual execution.
- Therefore, there comes a need for a turn variable.
Note:
- The Lock variable is defined as a synchronization mechanism for the processes.
- The lock variable mechanism is implemented in the user mode and is used to synchronize more than two processes.
Example: Consider we have two processes process P1 and process P2. For the below two processes P0 and P1,
- Turn value = 0: When the turn value is set to 0, it means that process P0 will enter into the critical section.
- Turn value = 1: When the turn value is set to 1, it means that process P1 will enter into the critical section.
Turn Variable in Operating System
The turn variable is defined as a synchronization mechanism that is implemented in the user mode. The turn variable is also known as the Strict Alternation Approach. It is a synchronization mechanism that is implemented for synchronizing two processes. For synchronization, it makes use of a variable known as the turn variable. This approach is used only when working with two processes.