9. (10) A Barbershop consists of a waiting room with n chairs, and the barber ro
ID: 3598816 • Letter: 9
Question
9. (10) A Barbershop consists of a waiting room with n chairs, and the barber room containing the 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 taken, then the customers wil leave 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. Write pseudocode using semaphores to coordinate the barber and the customers. Define the following variables: shared int vacant_chairs-n; //represents vacant chairs in barber sho semaphore mutex=1; //handles m.e· when clients access vacant-chairs semaphore barber-chair=1; //handles me. when clients access barber semaphore customer_in-0; //handles synch between barber and custome semaphore hair_cut_done 0; //handles synch between barber and custo Assume one barber thread and several customer threads. The barber thread is given belowExplanation / Answer
void *barberchair();
void *waitingRoom();
void checkQueue();
pthread_mutex_tqueue_mutex=PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t wait_mutex =PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t barberWorking_cond = PTHREAD_COND_INITIALIZER;
int returnTime=5,current=0, sleeping=0, iseed;
{
//DECLARE BARBER THREAD//
BARBER Thread
{
for( ; ;)
{
P (customer_in)
cut the customers hair
V (hair _cut _done)
}
}
pthread_attr_t customer;
}
#include <stdio.h>Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.