0% found this document useful (0 votes)
39 views1 page

Problem: The Analogy Is Based Upon A Hypothetical Barber Shop With One Barber. There Is A Barber

The document describes the barber problem and its solution using semaphores. The barber problem involves one barber, one barber chair, and multiple customer chairs. Customers either wait in chairs or leave depending on availability. The solution uses three semaphores - one for tracking customers waiting, one indicating if the barber is busy, and a mutex for mutual exclusion. When a customer arrives, they check chair availability and either sit and wait their turn or leave if no chairs remain. The barber sleeps until woken by a customer signal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views1 page

Problem: The Analogy Is Based Upon A Hypothetical Barber Shop With One Barber. There Is A Barber

The document describes the barber problem and its solution using semaphores. The barber problem involves one barber, one barber chair, and multiple customer chairs. Customers either wait in chairs or leave depending on availability. The solution uses three semaphores - one for tracking customers waiting, one indicating if the barber is busy, and a mutex for mutual exclusion. When a customer arrives, they check chair availability and either sit and wait their turn or leave if no chairs remain. The barber sleeps until woken by a customer signal.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Problem : The analogy is based upon a hypothetical barber shop with one barber.

There is a barber
shop which has one barber, one barber chair, and n chairs for waiting for customers if there are any
to sit on the chair.
• If there is no customer, then the barber sleeps in his own chair.
• When a customer arrives, he has to wake up the barber.
• If there are many customers and the barber is cutting a customer’s hair, then the remaining
customers either wait if there are empty chairs in the waiting room or they leave if no chairs
are empty.
Solution : The solution to this problem includes three semaphores.First is for the customer which
counts the number of customers present in the waiting room (customer in the barber chair is not
included because he is not waiting). Second, the barber 0 or 1 is used to tell whether the barber is
idle or is working, And the third mutex is used to provide the mutual exclusion which is required for
the process to execute. In the solution, the customer has the record of the number of customers
waiting in the waiting room if the number of customers is equal to the number of chairs in the
waiting room then the upcoming customer leaves the barbershop.
When the barber shows up in the morning, he executes the procedure barber, causing him to block
on the semaphore customers because it is initially 0. Then the barber goes to sleep until the first
customer comes up.
When a customer arrives, he executes customer procedure the customer acquires the mutex for
entering the critical region, if another customer enters thereafter, the second one will not be able to
anything until the first one has released the mutex. The customer then checks the chairs in the
waiting room if waiting customers are less then the number of chairs then he sits otherwise he
leaves and releases the mutex.

You might also like