Home > Operation and Maintenance > Linux Operation and Maintenance > What is a critical section in linux

What is a critical section in linux

藏色散人
Release: 2023-04-18 10:27:20
Original
2440 people have browsed it

Linux critical section refers to the program in each process that accesses critical resources. 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 it is not allowed after entry. Other processes enter.

What is a critical section in linux

#The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

1. What is a critical section?

Answer: The program 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.

2. The scheduling principle for processes entering the critical section is:

① If there are several processes requesting to enter the idle critical section, only one process is allowed to enter at a time. ②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. ③The process entering the critical section must exit within a limited time so that other processes can enter their critical section in time. ④ If the process cannot enter its own critical section, it should give up the CPU to avoid the "busy waiting" phenomenon of the process.

The mutex object is the simplest kernel object, which can be used to easily achieve mutually exclusive access to a certain resource. Because it is a kernel object, it can generate signals. In fact, this is used in the program to achieve mutual exclusion.

If I remember correctly, the critical section is not a kernel object, but a data structure provided by the system. You can declare a variable of this type in the program and then use it to achieve mutually exclusive access to resources. When you want to access a critical resource, first lock the critical section (if the critical section is not idle, wait), and after using up the resource, release the critical section.

Generally, they are used for synchronization between threads, and can usually be used interchangeably.

If you want to implement complex mutual exclusion, you should use other methods, such as semaphore kernel objects, etc. Critical section objects cannot span processes and are synchronization objects for shared data areas between threads; mutex objects can be used as synchronization objects for shared data areas between processes.

Recommended learning: "linux video tutorial"

The above is the detailed content of What is a critical section in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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