编程人 cdmana.com

Operating system - PV operation

PV Examples of operation :

analysis : Enter the bookstore P(Sn) And leaving the bookstore V(Sn) Operate in the corresponding topic “ The bookstore allows at most n A Book buyer enters ”, Because if the number of people entering the bookstore exceeds the maximum limit ,P The operation will be blocked , know V Free up space after operation .

Next, analyze the process of book purchase and charging , In real life, payment for book purchase is after the customer puts forward the demand for payment , Only the cashier can charge . So the cashier is in standby mode by default, that is, blocking mode , therefore b1 It's a P operation , Corresponding a1 It's a V operation , Wake up the cashier .

After paying the cashier, the customer will wait for the cashier to make change , Billing , You don't leave the bookstore until after degaussing . So in the process of payment a2 In this stage, customers will be in standby mode, that is P operation , Rechargeable b2 The stage is a V operation .

Back to the first space in the title, you should choose V,P Medium S1 or S2, Corresponding A Options ; Second, you should choose P,V Medium S1 or S2, Because the first air chose a1 => V(S1) and a2 => P(S2), therefore b1 To work with a1 The corresponding semaphore is P(S1),b2 And a2 The corresponding semaphore is V(S2).

 

 

 

PV Examples of operations and antecedents :

 

analysis : The key to solving the problem is marking 4 A semaphore S1,S2,S3,S4; From left to right , The top-down principle , stay P1 -> P3 Inter marker S1, stay P2 -> P3 Inter marker S2, stay P3 -> P4 Inter marker S3, stay P3 -> P5 Inter marker S4.

It can be concluded from the former trend diagram that P3 Need to wait P1 and P2 Only when the execution is completed can the execution be continued , therefore P1 The corresponding is V1,P2 The corresponding is V2, The first blank C;

P3 By P1 and P2 Blocking , So there will be P(S1) and P(S2), also P3 blocked P4 and P5, So it also has V(S3) and V(S4), The second blank A; that P4 and P5 By P3 Blocking , therefore P4 Yes P(S3) operation ,P5 Yes P(S4) operation ; The third blank A;

 

 

Scroll to Top