Interest Variable | Process Synchronization

Spread the love

Process Synchronization-

 

Before you go through this article, make sure that you have gone through the previous article on Process Synchronization.

 

We have discussed-

  • Process Synchronization provides a synchronization among the processes.
  • Synchronization mechanisms allow the processes to access critical section in a synchronized manner.
  • This avoids the inconsistent results.

 

Interest Variable-

 

  • Interest variable is a synchronization mechanism that provides synchronization among two processes.
  • It uses an interest variable to provide the synchronization.

 

It is implemented as-

 

 

Initially, interest [0] and interest [1] are set to False.

  • Interest value [0] = False means that process P0 is not interested to enter the critical section.
  • Interest value [0] = True means that process P0 is interested to enter the critical section.
  • Interest value [1] = False means that process P1 is not interested to enter the critical section.
  • Interest value [1] = True means that process P1 is interested to enter the critical section.

 

Working-

 

This synchronization mechanism works as explained in the following scenes-

 

Scene-01:

 

  • Process P0 arrives.
  • It sets interest[0] = True.
  • Now, it executes while loop condition- interest [1] == True.
  • Since interest [1] is initialized to False, so it returns value 0 to the while loop.
  • The while loop condition breaks.
  • Process P0 enters the critical section and executes.
  • Now, even if process P0 gets preempted in the middle, process P1 can not enter the critical section.
  • Process P1 can not enter unless process P0 completes and sets the interest [0] = False.

 

Scene-02:

 

  • Process P1 arrives.
  • It sets interest[1] = True.
  • Now, it executes while loop condition- interest [0] == True.
  • Process P0 has already shown its interest by setting interest [0] = True.
  • So, it returns value 1 to the while loop.
  • The while loop condition satisfies.
  • The process P1 is trapped inside an infinite while loop.
  • The while loop keeps the process P1 busy until the interest [0] value becomes False and its condition breaks.

 

Scene-03:

 

  • Process P0 comes out of the critical section and sets the interest [0] value to False.
  • The while loop condition of process P1 breaks.
  • Now, the process P1 waiting for the critical section enters the critical section and execute.
  • Now, even if process P1 gets preempted in the middle, process P0 can not enter the critical section.
  • Process P0 can not enter unless process P1 completes and sets the interest [1] = False.

 

Also Read- Criteria For Synchronization Mechanisms

 

Characteristics-

 

The characteristics of this synchronization mechanism are-

  • It ensures mutual exclusion.
  • It does not follow strict alternation approach.
  • It ensures progress since if a process is not interested to enter the critical section, it never stops the other process to enter the critical section.
  • It is architectural neutral since it does not require any support from the operating system.
  • It is a busy waiting solution which keeps the CPU busy when the process is actually waiting.
  • It suffers from deadlock.
  • Since it suffers from deadlock, it does not guarantee bounded waiting.

 

How it suffers from deadlock?

 

  • This synchronization mechanism may cause deadlock between the processes.
  • Deadlock may occur through the following sequence of scenes-

 

Scene-01:

 

  • Process P0 arrives.
  • It sets interest[0] = True.
  • Now, it gets preempted and process P1 gets scheduled.

 

Scene-02:

 

  • Process P1 arrives.
  • It sets interest[1] = True.
  • Now, it gets preempted.

 

Scene-03:

 

  • Process P0 gets scheduled again.
  • Now, it can not break the while loop condition- interest [1] == True since process P1 has shown its interest for executing critical section before its arrival.
  • It keeps waiting in the infinite while loop for process P1 to complete its execution first.

 

Scene-04:

 

  • Later, Process P1 gets scheduled again.
  • Now, it also can not break the while loop condition- interest [0] == True since process P0 is also interested for executing critical section.
  • It keeps waiting in the infinite while loop for process P0 to complete its execution first.

Thus, both the processes are deadlocked.

 

To gain better understanding about Interest Variable,

Watch this Video Lecture

 

Next Article- Practice Problems On Synchronization Mechanisms

 

Get more notes and other study material of Operating System.

Watch video lectures by visiting our YouTube channel LearnVidFun

Summary
Interest Variable | Process Synchronization
Article Name
Interest Variable | Process Synchronization
Description
In Process Synchronization, Interest Variable is a synchronization mechanism that uses an interest variable to provide the synchronization among the processes. Processes are executed according to their interests.
Author
Publisher Name
Gate Vidyalay
Publisher Logo

Spread the love