1. What is a critical section?
A: The program that accesses critical resources in each process is called a critical section (a critical resource is a shared resource that only one process is allowed to use at a time). Only one process is allowed to enter the critical section at a time, and no other process is allowed to enter.
2, the process into the critical area of the scheduling principle is:
① If there are several processes that require access to an idle critical section, only one process is allowed to enter at a time.
② at any time, there must be more than one process in the critical area. If a process has entered its own critical section, all other processes attempting to enter the critical section must wait.
The process of ③ entering the critical zone exits within a limited time so that other processes can enter their critical areas in time.
④ If the process does not enter its own critical section, you should give up the CPU to avoid a "busy" phenomenon in the process.
The mutex object is the simplest kernel object, which can easily implement mutually exclusive access to a resource. Because it is a kernel object, it can generate a signal, in fact, the program is to use this to achieve mutual exclusion.
If you remember correctly, the critical section is not a kernel object, but rather a data structure provided by the system that can declare a variable of that type and then use it to implement mutually exclusive access to the resource. When you want to access a critical resource, the critical section is locking (if the critical section is not idle, waiting), and the critical area is freed when the resource is exhausted.
In general, they are used for synchronization between threads, and are often used interchangeably.
If you want to implement complex mutexes, you should use other methods, such as semaphore kernel objects. A critical section object cannot span a process, is a synchronization object that shares data extents between threads, and a mutex can be used as a synchronization object for shared data areas between processes.
"Goto" critical section, mutex object