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)