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.

Similar Reads

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....

Synchronization for Two Processes

Two Process Synchronization – Process P0...

Features of Turn Variable

Mutual exclusion: Mutual exclusion does not allow more than one process to access the same shared resource at the same time. Turn variable ensures mutual exclusion property. Progress: The turn variable does not guarantee progress. It follows the alteration approach strictly. Portability: The turn variable is implemented in user mode and does not require any kind of special instruction from the operating system. Therefore it provides portability. Bounded waiting: Each process gets the chance, once a previous process is executed the next process gets the chance therefore turn variable ensures bounded waiting. Deadlock: The turn variable is free from deadlock. Only one process is in a critical section at a time. Once the turn value is updated the next process goes into the critical section....

Conclusion

The turn variable is used to overcome the limitations of the lock variable. It is implemented in the user mode and for synchronization between two processes. Turn variable ensures mutual execution, portability, and bounded waiting and it is free from deadlock....

Frequently Asked Questions

Q.1: What is a variable in an operating system?...