OS Critical Section Problem

The problem of avoiding race conditions can also be formulated in an abstract way. Part of the time, a process is busy doing internal computations and other things that do not lead to race conditions.


However, sometimes a process may be accessing shared memory or files, or doing other critical things that can lead to races. That part of the program where the shared memory is accessed is called the critical section (CS).


If we could arrange matters such that no two processes were ever in their critical sections at the same time, we could avoid race conditions.Although this requirement avoids race conditions, this is not sufficient for having parallel
processes cooperate correctly and efficiently using shared data.


We need four conditions to hold to have a good solution:

1. No two processes may be simultaneously inside their critical sections.
2. No assumptions may be made about speeds or the number of processors.
3. No process running outside its CS may block other processes.
4. No process should have to wait forever to enter its CS.


In this section, we will examine various proposals for achieving mutual exclusion, so that while one process is busy updating the shared memory in its CS, no other process will enter its own CS region and cause problem. In our discussions we will consider two process pi (i=0 and i=1) in the form:


{common variable declarations and initializations}
while (TRUE) {
 {CS entry code}
 CS( ) ;
 {CS exit code}
 Non-CS( ) ;


Try Now – Operating Systems MCQs
Practice Now – Operating System Online Test