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