Mutual exclusion by using critical regions

Critical region is section of a program where shared memory is accessed. By using critical regions race conditions can be avoided if:

1) Two processes should not be simultaneously in their critical regions.

2) A process which is running outside its critical region should not block other processes.

3) A process should not have to wait forever to enter its critical region.

4) Assumptions should not be made for factors like number of CPU, and speed.

To understand this process lets have two processes, Process 1 and Process 2. As you can see in the figure, Process 1 enters critical region. After some time, Process 2 attempts to enter in critical region. Now as per the rule two processes cannot be in their critical region simultaneously, hence, Process 2 is blocked and it has to wait for Process 1. After some time Process 1 leaves its critical region. Now, Process 2 enters in its critical region. Thus, mutual exclusion is achieved.

Mutual exclusion by using critical regions

Leave a Reply