Operating system principle,

Source: Internet
Author: User

Operating system principle,

 

The operating system is used to manage the hardware, software, and data resources of the system and control the running of programs. It is an interface between the application software and hardware and an interface between humans and machines. Operating system functions include process management, storage management, file management, device management, and job management.

 

In process management, PV operations are very important in processing process synchronization and mutex issues. They are used when multiple processes need to access Shared resources at the same time. PV is short for Dutch. P indicates release, and V indicates release. It is said to be one of the few non-English abbreviations in the computer field.

 

A pv operation consists of a P operation primitive and a V Operation primitive. The primitive is also called an atomic operation, indicating an uninterrupted process. These two primitives need to operate the semaphore S.

In the P operation, the value of S is reduced by 1. If S is less than 0, the process is set to the waiting state and added to the process queue. Otherwise, the process continues.

The V Operation adds the value of S to 1. If S <= 0, the system will wake up the first process in the queue; otherwise, the system will continue to execute.

Next, we will describe the use of PV operations with single cache area producers and consumers. Because there is only one single cache area, the excessive production speed will cause the cache area to overflow, if the consumption speed is too fast, a null value will be obtained from the cache, which can be solved after the PV operation is added.

 

There are two processes: producer and consumer. Two PV operations are used. The initial value of S1 is 1, and the initial value of S2 is 0. For the first execution by the producer, S1 = 0, send the product to the cache zone, S2 = 1; for the second execution, S1 =-1, the producer process changes to the waiting status and joins the process queue. For the consumer process, S2 = 0 during the first execution, the product is obtained from the cache, S1 = 0, and the consumption product. Because S1 = 0, the producer process is awakened, in this case, the products in the cache area are consumed completely. Similarly, if the consumer process is executed first, the cooperation between the two processes can still be ensured.

PV Operations coordinate several processes that need to be synchronized through such a process.

 

 

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.