Question: 1C. Use the space below to complete the code for the customer threads. Recall: When a customer arrives, he checks the barber status. If the

1C. Use the space below to complete the code for the customer threads. Recall:

When a customer arrives, he checks the barber status. If the barbers sleeping, the customer wakes the barber up. Otherwise, the customer enters the waiting room.

If a seat is available, the customer takes it; otherwise, he leaves (without waiting)

There may be multiple barbers and customers, with up to N customers waiting in the waiting room. The solution requires three semaphores and a shared variable to track free seats in the waiting room, initialized as shown below. Assume semaphore is a valid type.

semaphore barbers=0; // # free barbers

semaphore customers=0; // #waiting customers

semaphore mutex=1; // used if mutual exclusion needed

int freeSeats=N; // # free seats in waiting room

You may write pseudo-code but should use appropriate semaphore functions when necessary.

Void customer () {

If ( _____________) //Check if seat available

get_haircut (); //actual work of getting haircut

}

Else{

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!