Critical section
In concurrent programming, concurrent accesses to shared resources can lead to unexpected or erroneous behavior.[src] Thus, the parts of the program where the shared resource is accessed need to be protected in ways that avoid the concurrent access.[src] One way to do so is known as a critical section or critical region.[src] This protected section cannot be entered by more than one process or thread at a time; others are suspended until the first leaves the critical section.[src] Typically, the critical section accesses a shared resource, such as a data structure, peripheral device, or network connection, that would not operate correctly in the context of multiple concurrent accesses.[src]
In concurrent programming, concurrent accesses to shared resources can lead to unexpected or erroneous behavior.[src] Thus, the parts of the program where the shared resource is accessed need to be protected in ways that avoid the concurrent access.[src] One way to do so is known as a critical section or critical region.[src] This protected section cannot be entered by more than one process or thread at a time; others are suspended until the first leaves the critical section.[src] Typically, the critical section accesses a shared resource, such as a data structure, peripheral device, or network connection, that would not operate correctly in the context of multiple concurrent accesses.[src] // Process A .[src] .[src] b = x + 5; // instruction executes at time = Tx .[src] Process B: // Process B .[src] .[src] x = 3 + z; // instruction executes at time = Tx .[src] In cases where a locking mechanism with finer granularity is not needed, a critical section is important.[src] In the above case, if A needs to read the updated value of , executing process A, and process B at the same time may not give required results.[src] To prevent this, variable is protected by a critical section.[src] First, B gets the access to the section.[src] Once B finishes writing the value, A gets the access to the critical section, and variable can be read.[src] By carefully controlling which variables are modified inside and outside the critical section, concurrent access to the shared variable is prevented.[src] A critical section is typically used when a multi-threaded program must update multiple related variables without a separate thread making conflicting changes to that data.[src] In a related situation, a critical section may be used to ensure that a shared resource, for example, a printer, can only be accessed by one process at a time.[src] ==See also== Database transaction Dekker's algorithm Eisenberg & McGuire algorithm Lamport's bakery algorithm Lock (computer science) Mutual exclusion Peterson's algorithm Szymański's algorithm ==References== ==External links== Critical Section documentation on the Microsoft Docs web page Tutorial on Critical Sections Code examples for Mutex Tutorial on Semaphores Lock contention in Critical Sections[src]
25 sentences · 25 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Critical section." encyclopegia.org, 2025, https://encyclopegia.org/wiki/critical-section. Accessed 25 November 2026.
Chicago
"Critical section." encyclopegia.org. Accessed November 25, 2026. https://encyclopegia.org/wiki/critical-section.
APA
encyclopegia.org. (2025). Critical section. Retrieved November 25, 2026, from https://encyclopegia.org/wiki/critical-section
Accessed November 25, 2026 · CC BY-SA 4.0 · citation page · JSON