Guidance for sleeping barber monitor solution

1.3k views Asked by At

I am trying to write a monitor solution for the sleeping barber problem using two barbers and customers of three types who are either waiting solely for barber 1, barber 2 or may not care which barber cuts their hair.

I was hoping for guidance on this problem -

My thoughts so far are that the algorithm will utilize a single list for the waiting customers and can use procedures such as

try_to_get_haircut()

if_not_first()

wake_up_barber()

wait_for_haircut()

1

There are 1 answers

0
aysebilgegunduz On

Below is one barber solution and i hope it'll guide for you.

monitor sleeping_barber{
 condition wait_for_cust, wait_for_barber ;
 int wait;
 entry barber{
   if (wait == 0) then cwait(wait_for_cust);
   wait = wait - 1;
   csignal(wait_for_barber); }

entry cut_customer_hair(){
 if(wait < seat_num)
 {
    wait = wait + 1;
    csignal(wait_for_cust);
    cwait(wait_for_barber);
    do_haircut();
 }
}
{ wait = 0;}}