Critical Section Routine

What Does Critical Section Routine Mean?

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.

Advertisements

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.

Techopedia Explains Critical Section Routine

The main requirements for implementing a CSR are:

  • Mutual Exclusion: When a process is executing in a CSR, no other process can enter.
  • Progress Condition: If no process is executing in a CSR and there are some processes that wish to enter it, they can do so in a definite amount of time. One of the processes enters the CSR while others wait.
  • Bounded Waiting: When a process requests to enter a CSR and before the request is granted, there must be an upper limit on the number of processes waiting to enter the CSR during this period to ensure that no process starves and every process in the waiting queue gets a turn to enter the CSR.

The CSR, in a certain piece of code, can be identified though the following properties:

  • Code is characterized by a read-write-update sequence of operations.
  • Sections of the code alter variables in another code, which performs a read-write-update sequence of operation.
  • The presence of code that accesses a data structure of some other code by modifying it, or code that uses a data structure that could be modified by some other process.

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.

Advertisements

Related Terms

Latest Software Development Terms

Related Reading

Margaret Rouse

Margaret Rouse is an award-winning technical writer and teacher known for her ability to explain complex technical subjects to a non-technical, business audience. Over the past twenty years her explanations have appeared on TechTarget websites and she's been cited as an authority in articles by the New York Times, Time Magazine, USA Today, ZDNet, PC Magazine and Discovery Magazine.Margaret's idea of a fun day is helping IT and business professionals learn to speak each other’s highly specialized languages. If you have a suggestion for a new definition or how to improve a technical explanation, please email Margaret or contact her…