Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The basic concept of process synchronization: critical capital, synchronization and mutual exclusion

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

In the case of multi-programming, the process is performed concurrently, and there are differences and mutual constraints between the divergent processes. In order to reconcile the mutual restriction between processes, the concept of process synchronization is introduced.

Critical capital

Although multiple processes can share all kinds of capital in bits and pieces, many of the capital can only be used by one process at a time. A lot of physical equipment belongs to critical capital, such as printers. In addition, there are many variables and data that can be shared by several processes, which also belong to critical capital.

The visit to the critical capital must be mutually exclusive. In each process, the code that visits the critical capital is called the critical area. In order to ensure the accurate use of critical capital, the visit process of critical capital can be divided into four parts:

Enter the zone. In order to enter the critical area and use the critical capital, we should reflect on whether we can enter the critical area. If we can enter the critical area, we should set up a mark that is visiting the critical area to prevent other processes from entering the critical area at the same time.

Critical area. The code that visits the critical capital in the process, also known as the critical section.

Join the area. Clear the mark that is visiting the critical area.

Residual area. Other parts of the code.

Do {entry section; / / entry Zone critical section; / / critical Zone exit section; / / join Zone remainder section; / / residual Zone} while (true) synchronization

Synchronization, also known as direct constraint relationship, refers to two or more processes established to fulfill certain obligations, and these processes wait and transmit information due to the rising status of certain requirements and the order of their tasks. The direct restriction between processes stems from the cooperation between them.

For example, the output process A supplies data to process B through a single buffer. When the buffer is empty, procedure B cannot get the required data and is congested. Once procedure A sends the data into the buffer, process B is woken up. On the contrary, when the buffer is full, process An is choked, and process An is awakened only when process B takes away the buffered data.

Mutual exclusion

Mutual exclusion is also called direct restriction relationship. When one process enters the critical zone and uses the critical capital, the other process has to wait, and when the process that occupies the critical capital is added to the critical zone, the other process is allowed to visit the critical capital.

For example, in bits and pieces with only one printer, there are two process An and process B. if process A needs to print, the printer has been assigned to process B, then process A must be congested. Once process B releases the printer, the odds and ends wake up process An and change it from a choked form to a proper form.

In order to prevent both processes from entering the critical zone at the same time, the synchronization mechanism should follow the following principles:

Let in at leisure. When the critical area is at leisure, a process of pleading to enter the critical area can be allowed to enter the critical area immediately.

If you are busy, you wait. When an existing process enters the critical zone, other processes that attempt to enter the critical zone must wait.

Waiting indefinitely. The process of pleading for a visit should be guaranteed to enter the critical area within an unlimited amount of time.

Let the right wait. When the process cannot enter the critical area, the processor should be released immediately to avoid busy waiting for the process.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report