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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started