Home > Common Problem > Critical section refers to what shared variables are accessed in concurrent processes

Critical section refers to what shared variables are accessed in concurrent processes

青灯夜游
Release: 2023-02-13 18:35:59
Original
14197 people have browsed it

The critical section refers to the program segment that accesses shared variables in concurrent processes. A critical section refers to a program fragment that accesses shared resources, and these shared resources cannot be accessed by multiple threads at the same time. Only one process is allowed to enter the critical section at a time, and other processes are not allowed to enter after entering.

Critical section refers to what shared variables are accessed in concurrent processes

The operating environment of this tutorial: Windows 7 system, Dell G3 computer.

The critical section refers to the program segment that accesses shared variables in concurrent processes.

Introduction to Critical Sections

A critical section refers to a program fragment that accesses shared resources (such as shared devices or shared memory), and these shared Resources cannot be accessed by multiple threads at the same time. When a thread enters a critical section, other threads or processes must wait (for example: bounded waiting waiting method). Some synchronization mechanisms must be implemented at the entry and exit points of the critical section to ensure that these shared resources are used. Mutex is used, for example: semaphore. Devices that can only be accessed by a single thread, such as printers.

The section of code in each process that accesses critical resources is called the critical section (critical resources are shared resources that are only allowed to be used by one process at a time). Only one process is allowed to enter the critical section at a time, and other processes are not allowed to enter after entering. Whether it is a hardware critical resource or a software critical resource, multiple processes must access it mutually.

Critical sections involving the same critical resource in multiple processes are called related critical sections. .

The scheduling principle for processes entering the critical section is:

1. If there are several processes requesting to enter the idle critical section, only one process is allowed to enter at a time.

2. At any time, there cannot be more than one process in the critical section. If a process has entered its own critical section, all other processes trying to enter the critical section must wait.

3. The process entering the critical section must exit within a limited time so that other processes can enter their critical section in time.

4. If the process cannot enter its own critical section, it should give up the CPU to avoid the "busy waiting" phenomenon of the process.

Related recommendations: "Programming Video"

The above is the detailed content of Critical section refers to what shared variables are accessed in concurrent processes. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template