Winter Semester 2026–27 · VIT-AP · BACSE106 · Operating Systems · Dr. Krithika L.B

The critical-section problem

Entry/exit structure and the three requirements.

Module 3 Session 3.2 Lesson 2 of 4

Operating Systems: The Critical-Section Problem

Mutual exclusion: the three requirements

1. Problem Formulation

Consider a system consisting of n processes {P0, P1, …, Pn−1}. Each process has a segment of code called a Critical Section (CS), in which the process may be updating shared variables, updating a table, writing a file, or modifying shared memory.

The Problem: When one process is executing in its critical section, no other process is allowed to execute in its critical section simultaneously. The critical-section problem is to design a protocol that processes can use to cooperate safely without data corruption or execution deadlocks.

2. Structure of a Typical Process (Pi)

To control access, each process must request permission to enter its critical section. The general execution loop of a process Pi is partitioned into four explicit code sections:

// Structure of a typical process Pi
do {
    entry section    critical section    exit section    remainder section} while (true);
1. Entry Section
Requests entry permission to access shared resources. Implements synchronization protocols such as Mutex locks, Peterson's variables, or Semaphores.
2. Critical Section (CS)
Executes operations on shared memory/data. Strict rule: Only one process can execute here at any instant.
3. Exit Section
Releases the lock or resets permission flags so that other blocked processes waiting in their entry sections can proceed.
4. Remainder Section
Executes independent local computations that do not involve shared resources.

3. Requirements for a Valid CS Solution

A valid solution to the critical-section problem must satisfy the following three fundamental criteria under all execution orderings:

1. Mutual Exclusion

If process Pi is executing in its critical section, then no other processes can be executing in their critical sections.

2. Progress

If no process is executing in its critical section and some processes wish to enter, only those processes not executing in their remainder section can participate in deciding which process will enter next. This selection cannot be postponed indefinitely.

3. Bounded Waiting

There must be a bound or limit on the number of times that other processes are allowed to enter their critical sections after a process has made a request to enter and before that request is granted.

4. Interactive Critical Section Protocol Simulator

Experiment below by requesting entry for Process 0 (P0) and Process 1 (P1). Switch between **Peterson's Algorithm** (enforces all 3 rules) and **Unsynchronized Mode** (causes race conditions).

Process P0

Remainder Section

Process P1

Remainder Section
Shared Protocol State: flag[0]=false, flag[1]=false, turn=0 | Active CS: None
MUTUAL EXCLUSION VIOLATED! Both Process P0 and Process P1 are executing inside the Critical Section simultaneously! Data corruption will occur!