Operating System - Requirement for solution to critical section

What is a Critical Section?

A Critical Section is a part of a program (usually involving shared resources) where only one process or thread should execute at a time.

It is used in concurrent programming when multiple processes or threads access shared resources (like variables, files, or printers).

Prevent race conditions, where multiple processes access and modify shared data simultaneously, leading to inconsistent results.

Structure of a Process with a Critical Section

A typical process has these sections:

  1. Entry Section – Code that requests permission to enter the critical section.

  2. Critical Section – The part where shared resources are accessed.

  3. Exit Section – Code that releases control after leaving the critical section.

  4. Remainder Section – All other code.

Requirements for a Critical Section Solution

To ensure safe and fair access, a solution to the Critical Section Problem must satisfy three essential conditions:

1. Mutual Exclusion

  • Only one process can be in the critical section at any time.

  • If a process is in the critical section, all others must wait.

2.  Progress

  • If no process is in the critical section, and some processes wish to enter, then only those processes participating in the decision must determine who gets in next.

  • No process outside the decision-making should affect the choice.

3.Bounded Waiting

  • A process waiting to enter the critical section should have a limited wait time.

  • Prevents starvation — ensures fairness.

  • There should exist a bound on how many times other processes can enter their critical section before a waiting process is allowed to enter.