Critical Section - aryanjoshi0823/5143-Operating-System GitHub Wiki

What is a Critical Section?

The critical section in an operating system refers to a segment of code where shared resources (like variables, files, or hardware) are accessed. Ensuring that no two processes are in their critical sections at the same time is crucial for maintaining consistency and avoiding conflicts.


Critical Section Problem

The problem arises when multiple processes attempt to execute their critical sections concurrently.

A solution must satisfy three key conditions:

  1. Mutual Exclusion: Only one process can access the critical section at a time.
  2. Progress: Processes outside their critical sections should not prevent others from entering.
  3. Bounded Waiting: There is a limit to how long a process waits before entering the critical section.

Structure of a Process with a Critical Section

  1. Entry Section: Code to request entry into the critical section.
  2. Critical Section: Code where shared resources are accessed.
  3. Exit Section: Code to signal the end of the critical section.
  4. Remainder Section: All other code outside these sections.