CREATE OWN LIBRARY

Race Condition and Critical Section 

 

 

In the above program, the critical section of P1 is Count ++ and P2 is Count --.

 

Now we write the assembly code for P1 and P2:

 

 

If P1 and P2 processes run one after another or simultaneous way in the serial manner then there no problem with data inconsistency.

 

For example

 

P1: 1, 2, 3                   P2:  1, 2, 3                   c = 5

 

But sometimes data inconsistency problems arise when two processes running simultaneously but in no serial manner.

 

For example

 

c = Count

 

1) P1:  1, 2                P2:  1, 2, 3                   P1:  1                                       c = 6

2) P2:  1, 2                P2:  1, 2                       P1:  1               P2:  3               c = 4

 

In two different cases, we got two different answers because of sharing the same memory space. 

So, when shared memory or common space or common resources is used, then it leads to a race condition

 

 

To avoid this unavoidable inconsistency problem or race condition, we use process synchronization.

 

Problems can occur due to a lack of synchronization

i)  Loss of data

ii) Inconsistency (wrong result)

iii) Race condition

iv) Dead Locks