LOCK VARIABLE




Simplest synchronization mechanism-implemented in User mode-used for more than two processes.
// two values-0,1. 0 means critical section is vacant and 1 means critical section is occupied.

Analysis of Lock Variable:


The lock variable mechanism doesn't provide Mutual Exclusion in some of the cases. This can be better described by looking at the pseudo code by the Operating System point of view I.E. Assembly code of the program. Let's convert the Code into the assembly language.
Load Lock, R0
CMP R0, #0
JNZ Step 1
Store #1, Lock
Store #0, Lock

The problem with the lock variable mechanism is that, at the same time, more than one process can see the vacant tag and more than one process can enter in the critical section. Hence, the lock variable doesn't provide the mutual exclusion that's why it cannot be used in general. Since, this method is failed at the basic step; hence, there is no need to talk about the other conditions to be fulfilled.

Demo

Steps

Lights

Input

Enter the number of process required and that will be shown in the added state.

For processing the process further click on the respective process and that will be added to the new state according to the algorithm or alert will be shown.

Output

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

The lock state is shown above the added state according to the process in the critical state.

Lights