PV operation--study on soft test (v)

Source: Internet
Author: User

Prior to summarizing the resource-related banker algorithms, as the study deepened, the understanding of the resources also have a deeper understanding, this article by solving the synchronous, asynchronous problem of the typical mechanism--PV operation to deepen the understanding of resources.

P Action: Request a resource. It is a prerequisite for performing operations, and only resources are available to perform operations. Is the same as real life, only with the resources to be able to produce.

v Operation: Frees a resource. After the completion of an operation to release the resources used, and the banker algorithm to match, and signal.

" Example " two associated processes A and B, they share a buffer. Process a continuously reads the data and feeds into the buffer, and process B continuously extracts the data from the buffer and processes it. So there are two processes in the constraints of the relationship, you can use the PV operation to solve.

Now declare two signals S1, S2, respectively, representing the two states of process A and process B, when process a reads the data and feeds into the buffer, completes its own read work, and signals that process B can come to the buffer to fetch the data, when process B gets the signal, Remove the data from the buffer after processing, the signal is signaled that process a can continue to perform its work, which is the relationship between the two of them. The PV primitives for this process are as follows:

Begin

S1,s2:semaphore;

S1:=1,s2:=1;

Cobegin

Process P1

Begin

L1:p (S1);

V (S2);

Go to L1;

End

Process P2

Begin

L2:p (S2);

V (S1);

Go to L2;

End

Coend;

end;  

PV operation solved the problem:

1. Successfully resolved the conflict of the synchronization process;

2. Realize the synchronization of the process and the mutual exclusion of shared resources;

Of course, for the PV operation of their own understanding is also very superficial, just the tip of the iceberg, to be improved, hope that the great God of many advice!

PV operation--study on soft test (v)

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.