0% found this document useful (0 votes)
747 views

Sleeping Barber Problem

The Sleeping Barber Problem describes an inter-process communication issue that can occur between a barber, customers, and limited waiting room chairs in a barbershop. The barber sleeps when no customers are waiting, but must be awakened when a customer arrives. Customers may have to wait in the chair if the barber is busy or leave if the waiting room is full. This can cause the barber and customers to unintentionally wait for each other. The solution is to use a mutex lock to ensure only one participant can change state at a time - such as the barber checking for customers or a customer entering the shop.

Uploaded by

Chikku
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
747 views

Sleeping Barber Problem

The Sleeping Barber Problem describes an inter-process communication issue that can occur between a barber, customers, and limited waiting room chairs in a barbershop. The barber sleeps when no customers are waiting, but must be awakened when a customer arrives. Customers may have to wait in the chair if the barber is busy or leave if the waiting room is full. This can cause the barber and customers to unintentionally wait for each other. The solution is to use a mutex lock to ensure only one participant can change state at a time - such as the barber checking for customers or a customer entering the shop.

Uploaded by

Chikku
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

SLEEPING BARBER

PROBLEM

A CLASSICINTER-PROCESS COMMUNICATION
&SYNCHRONIZATIONPROBLEM
BETWEEN MULTIPLEOPERATING
SYSTEMPROCESSES

HYPOTHETICAL BARBER SHOP CONDITIONS


Barber shop - one barber; many customers.
A waiting room - with N chairs.
One customer is served at a time.
Barber,
Barber sleeps when no customers are waiting.
Customer leaves if shop is full.

THE SLEEPING BARBER PROBLEM


(CONTD)
When barber finishes cutting a customer's hair, he checks if
there are any waiting customers:
Any waiting customers : barber cuts his hair.
No customers waiting : barber sleeps.

When each customer arrives, he checks what the barber is


doing:
Barber sleeping : customer wakes him up.
Barber cutting hair: customer goes to waiting room.
A free chair : customer sits in it.
No free chair : customer leaves.
4

PROBLEMS
Both barber and customer waits for each other :
o customer arrives - barber is busy
o Customer on his way to waiting room, barber finishes hair cut.
o Barber goes to sleep, Customer waits.

Customers competing for the same chair:


o Two customers single chair.
o Both attempt to occupy the single chair.

SOLUTION
Mutex :
Ensures that only one of the participants can change
state at once.
The barber must acquire this mutex before checking for
customers and release it when he begins either to sleep
or cut hair.
A customer must acquire it before entering the shop and
release it once he is sitting in either a waiting chair or the
barber chair.
6

PSEUDOCODE

THANK YOU..

You might also like