"Goto" critical section, mutex object

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.