barbershop consists of a waiting room with n chairs and a barber room with one b
ID: 3761201 • Letter: B
Question
barbershop consists of a waiting room with n chairs and a barber room with one barber chair. If there are no customers to be served, the barber goes to sleep. If a customer enters the barbershop and all chairs are occupied, then the customer leaves the shop. If the barber is busy but chairs are available, then the customer sits in one of the free chairs. If the barber is asleep, the customer wakes up the barber. Using POSIX Semaphores, write a multithreaded C program to coordinate the barber and the customers.
Explanation / Answer
class CBarberShop { private: int m_NoWaitingChairs,m_NoCustomers; const int MAX_CHAIRS; bool m_BarberStatus,IsRandEven; public: CBarberShop():MAX_CHAIRS(5) //Constructor initializing variables { m_NoWaitingChairs=5; m_NoCustomers=0; m_BarberStatus=false; } bool Barber_Status() //returns the barber's status. true=busy; false=free; { } void Wakeup() // if the barber is sleeping customer wakes him up { } //constantly checks for new customer arriaval. If the random number is even, it triggers // new customer arrival. if random number is odd, no trigger. void Check_For_New_Customer() { } //while barber doing haircut. decrease no.of customers and increase waiting chairs. void Haircut() { } //gets the current customer and seats info void Get_Customer_Seat_Status() { } // sets the barber status to true or false depending on the customers. void Set_Barber_Status(bool status) { } //returns no.of customers at any time int No_Customers() { } //retuns no. of waiting chairs availalbe at any time int No_WaitChairs_Available() { } bool IsEven(int x) { } };
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.