operating-system-process-critical-section.html


* created: 2025-05-18T21:23
* modified: 2025-06-30T21:35

title

Critical section

description

The part of a process needs exclusive access to a resource like the SSD for example.

related notes

Ensuring exclusive access

During a critical section of a process has exclusive access to a shared resource. A example of this would be the write to a SSD, during which no other process should be allowed to access the same resource. This ensures that we don't collide with another process that also want's to write to the same section.

This exclusive access does not automatically mean, that the process can't be interrupted. In some cases it's quite the opposite. When dealing with slow I/O operations the process still switches into a blocked state, which intern frees the CPU during the process, but the SSD, for example, would still be blocked during this time.

Can two processes be in a critical section at the same time?

Yes, if they are not trying to use the same resource. Critical sections are not for denoting important work; they are just for ensuring mutual exclusion (see semaphores).

So if one process writes to a shared disk and another is updating a shared structure in RAM, there should be no issue. They just can't access the same critical section.