ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > ZSTU class(2019-2020-1) > student directories > >
homework4 Version 0
👤 Author: by 335417758qqcom 2019-10-07 13:24:13
A barber's shop has a barber, a barber's chair, and many waiting chairs. When there are no customers, the barber goes to bed. When a customer comes to the shop, if the barber is sleeping, wake up the barber; otherwise sit and wait; if the waiting chairs are full, leave.

 

Int sum=0;   //The number of waiting customer

Int chairs=5;  //The chair for waiting customer

Semaphore customers=0,barbers=0,mutex=1;

 

Barber procedure:

While(TRUE){

  wait(customers);

  wait(mutex);

  sum=sum-1;

  signal(barbers)

  signal(mutex)

  Cut-hair();

}

 

Customer:

Waiting(mutex)

If(sum<chairs){

  Sum=sum+1;

  Signal(customers)

  Signal(mutex);

  Waiting(barber);

  Get_haircut();

}

Else signal(mutex)

 

 

 

Please login to reply. Login

Reversion History

Loading...
No reversions found.