ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > CLASS (2016-2017-1)-62903-06102-1 > 2014329600026吴宪 >
homework4-6.11 Version 0
👤 Author: by wuxian 2017-01-01 14:58:25


 

semaphore Scuthair, Snumchair;

Scuthair=0; Snumchair=0;

 

barber:

do {

wait(Scuthair);//Check whether there is a customer, no sleep

/*Give a customer a haircut*/

signal(Snumchair);//Let the barber finished the customer to quit, so that waiting for a customer to enter

} while (1);

 

Customer i:

wait(Snumchair);//Apply for a chair

signal(Scuthair);//Send a signal to the barber

Sitting in a chair waiting for a haircut! // Shared variables

semaphore Scuthair, Mutexchair;// Scuthair to the barber, Mutexchair restricting customers to the mutual occupation of the chair

int number = 0;//Customer’s shared variable, record the number of customers already

Scuthair=0; Mutexchair =1;

 

Custome

Please login to reply. Login

Reversion History

Loading...
No reversions found.