BCA / B.Tech 12 min read

Critical Section in Operating System

Critical Section in Operating System:


A Critical Section is a part of a program where shared resources are used. These resources can also be accessed by other processes, so it's crucial that when one process is in its critical section, no other process can access that resource at the same time. The critical section problem mainly arises in multiprocessing or multithreading systems where multiple processes or threads want to use the same resource simultaneously.

Synchronization is needed to solve this problem, so that processes can work independently without issues like data inconsistency or data races. Various protocols and algorithms are used to solve the critical section problem, ensuring that only one process can enter the critical section at any given time.

The Critical Section Problem:

This problem arises when multiple processes use the same shared resource simultaneously. If not controlled properly, it can lead to:
  • Race Condition: Occurs when multiple processes access or modify shared data at the same time, leading to an inconsistent and unpredictable final output.
  • Data Inconsistency: Improper use of shared resources can cause data to become incorrect or incomplete.
  • Deadlock: Occurs when two or more processes are waiting for each other's resources and none can proceed.

Conditions for a Solution:

A solution to the critical section problem must satisfy three important conditions:
  • Mutual Exclusion: Ensures that only one process can be in the critical section at a time.
  • Progress: If no process is in its critical section, and some processes wish to enter, the selection of the next process to enter cannot be postponed indefinitely.
  • Bounded Waiting: There must be a limit on how long a process has to wait to enter its critical section.

Methods to Solve the Critical Section Problem:

  1. Peterson's Algorithm: An algorithm designed to solve the critical section problem between two processes.
  2. Lock and Unlock: The most common solution where a resource is locked before use and unlocked after. Implemented using Mutexes and Semaphores.
  3. Semaphore: A synchronization tool that can be a Binary Semaphore (for mutual exclusion) or a Counting Semaphore (for multiple resources).
  4. Monitors: A high-level synchronization tool that automatically guarantees mutual exclusion.
  5. Test and Set: A hardware-based solution that uses a special instruction to atomically check and set a shared variable.

Examples of Critical Sections:

  • Bank Transaction: Ensures only one transaction can access account information at a time.
  • Printer Use: Ensures only one process can access the printer at a time.

In this Chapter

Critical Section in Operating System
Distributed System in Operating System
Real-Time System in Operating System
System Calls in Operating System
System Programs in Operating System
Structure of an Operating System
Layered Design of an Operating System Structure
UNIX in Operating System
Virtual Machine in Operating System
Kernel-Based Operating System
Process Concept in Operating System
Interacting Processes in Operating System
Threads in Operating System
Fundamentals of Scheduling in Operating System
Scheduling Criteria in Operating System
Long, Medium, and Short-Term Scheduling
Scheduling Algorithms in Operating System
Structure of a Concurrent System
Critical Region in Operating System
Inter-process Communication (IPC) in Operating System
Monitors in Operating System
Semaphores in Operating System
Semaphore Implementation & Uses in Operating System
Logical and Physical Address in Operating System
Swapping in Operating System
Contiguous Allocation in Operating System
Segmentation in Operating System
Paging in Operating System
Virtual Memory using Segmentation in Operating System
Interprocess Communication Protocol in Operating System
Network Operating System
Design Issues in Distributed File System
Network Structure in Operating System
Structure of a Distributed System
File System and Coordination in Operating System
History of Linux in Operating System
Linux Commands
Programmer Interface & File Manipulation in Linux
Process Control in Linux
Kernel & Signals in Linux
File System in Linux
Blocks and Inodes in Linux
System Editors in Linux
Character Transliteration in Linux
The `ed` Line Editor in Linux
The `vi` Editor and Its Commands
Shell Scripting in Linux
Looping & Decision Making in Linux Shell Scripting
Variables & File Name Expansion in Linux
Arrays in Linux Shell Scripting
Subprograms (Functions) in Linux Shell Scripting
C Interface with Linux
Simple Shell Programs in Linux
BCA Part-1 | Operating Systems | Semester-I | MDSU Exam Paper 2023 (Held in 2024)
What is an Operating System (OS)
Operating System (OS) All Important Questions and Answers in English (MDSU)
BCA || Operating System 2025 Paper || MDSU Exam Paper
BCA | OS(Operating System) 2023 Paper | MDSU Exam Paper
Types of Operating Systems
Goals of an Operating System
Operations of an Operating System
Resource Allocation & Functions in an Operating System
Classes of Operating System
Batch Processing in Operating System
Multiprocessing in Operating System
Time-Sharing in Operating System