Tech moves fast! Stay ahead of the curve with Techopedia!
Join nearly 200,000 subscribers who receive actionable tech insights from Techopedia.
Critical section routine (CSR) is a section of code for which a process obtains an exclusive lock so that no other process may execute it simultaneously. Often, one or more processes execute simultaneously in an operating system, forcing these processes to compete with each other for access to files and resources. Only one process should be allowed to access the resource while part of the code related to the resource is executed.
To ensure that a process in the CSR does not fail while other processes are waiting, a time limit is set by the process management component. Thus, a process can have access to an exclusive lock for only a limited amount of time.
The main requirements for implementing a CSR are:
The CSR, in a certain piece of code, can be identified though the following properties:
The concept of critical section can be applied to hardware that uses the interrupts facility. Whenever a process enters a critical section, all interrupts on the processor should be disabled so that other processes cannot request a lock on the resource. Similarly, when a process finishes execution, interrupts are enabled again. Another approach is to use a semaphore, a special variable that acts like a signal to direct the execution or termination of a process.