---
title: "Critical section problem; why execute quickly"
subject: "Operating System"
chapter: 3
key: "semester_6/operating_system:critical-section-thread-quick"
source: https://www.bctengineer.com/q/semester_6/operating_system/critical-section-thread-quick
site: BCT Engineering
---

# Critical section problem; why execute quickly

Operating System · Chapter 3: Process Communication and Synchronization

- Asked in: 2073 Bhadra, 5 marks
- Video: [The Critical-Section Problem](https://www.youtube.com/watch?v=UtEORPakw5Y) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/critical-section-thread-quick
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-3

## Question

Explain the Critical Section problem. Why is it important for a thread to execute a critical section as quickly as possible?

## Short answer

The critical section problem is designing a protocol so threads accessing shared data in their critical sections satisfy mutual exclusion, progress and bounded waiting. A thread should leave its critical section quickly because waiting threads may spin or block, wasting CPU and causing lock contention, delays, priority inversion or starvation.

## Answer

#### The critical section problem

Several threads (or processes) share data. The part of the code that accesses shared data is the **critical section**. If two threads execute it at the same time, the data may be corrupted and the result depends on the order of execution (a race condition). The critical section problem is to design a protocol that all threads follow, so that when one thread is inside its critical section no other thread is allowed to be inside its own critical section for the same data.

Each thread consists of:
- **entry section**: request permission to enter;
- **critical section**: access to shared data;
- **exit section**: release permission;
- **remainder section**: other code.

A correct solution satisfies three requirements:
1. **Mutual exclusion**: only one thread in the critical section at a time.
2. **Progress**: if no thread is in the critical section, one of those wanting to enter is chosen without indefinite delay; threads outside do not block it.
3. **Bounded waiting**: a limit on how many times others can enter before a waiting thread gets in (no starvation).

Typical solutions are Peterson's algorithm, TSL/atomic instructions, mutex locks, semaphores and monitors.

#### Why should a thread leave its critical section quickly?

- While one thread holds the lock, all the other threads that want it are **blocked or spinning**; a long critical section makes them wait, reducing concurrency and throughput.
- With **spin locks** waiting threads waste CPU cycles in busy waiting.
- A long critical section increases **lock contention** and the response time of the whole system, and may lead to **starvation** of waiting threads.
- A **higher-priority thread** waiting for a lock held by a low-priority thread is delayed (priority inversion).
- If the holder is slow or blocks (e.g. waits for I/O inside the critical section), it can cause long delays or even deadlock.

Hence critical sections should hold only the minimum code needed to access shared data, and do no I/O or lengthy work inside.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does the critical section problem ask for?
   A. Faster CPU scheduling
   B. A protocol so only one thread is in its critical section for the same data
   C. Memory allocation for threads
   D. Disabling all threads
   Answer: B. A protocol must ensure that while one thread is inside, no other thread enters its critical section on the same data. (Key point: Critical section problem)

2. What does the progress requirement say?
   A. Only one thread inside at a time
   B. Threads must finish within a time limit
   C. If none is inside, a waiting thread is chosen without indefinite delay, and outsiders do not block it
   D. Each thread enters in fixed order
   Answer: C. Progress means threads outside the critical section cannot stop others from entering; mutual exclusion and bounded waiting are separate. (Key point: Solution requirements)

3. Why should a thread leave its critical section quickly?
   A. To save memory
   B. Because other threads are blocked or spinning, reducing concurrency and wasting CPU
   C. To avoid creating the entry section
   D. Because the compiler requires it
   Answer: B. Others wait during the whole time; with spin locks they burn CPU, and contention and starvation grow. (Key point: Why be quick)

4. What problem arises if a low-priority thread holds a lock for long?
   A. A higher-priority thread waiting for the lock is delayed
   B. The low-priority thread is killed
   C. The lock is freed automatically
   D. Nothing, priorities are ignored
   Answer: A. The higher-priority thread must wait for the low-priority holder, called priority inversion. (Key point: Priority inversion)

## Related in Operating System

- [Race condition; critical section approaches](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Arace-condition-critical-section-approaches) — Operating System, chapter 3
- [Critical section; mutual exclusion](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Acritical-section-mutual-exclusion-pc) — Operating System, chapter 3
- [Process vs thread; context switching](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Athread-context-switching) — Operating System, chapter 2

## Related in other subjects

- [Contraction to 1.25 m: is flow possible?](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Acontraction-possible-flow-specific-energy-4m-channel) — Hydraulics, chapter 7
- [TCTO numerical: crashing critical path, Rs 30/day](https://www.bctengineer.com/question.md?key=semester_8%2Fconstruction_management%3Atcto-2069-bhadra) — Construction Management, chapter 2
- [Critical position of UDL shorter than span](https://www.bctengineer.com/question.md?key=semester_4%2Ftheory_of_structures_i%3Audl-shorter-than-span-critical-position) — Theory of Structures I, chapter 5, asked 6×
- [Critical flow conditions and 3 m to 2 m contraction](https://www.bctengineer.com/question.md?key=semester_4%2Fhydraulics%3Acontraction-hump-conditions-critical-flow-and-bed-rise) — Hydraulics, chapter 7, asked 2×
