Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Sleeping barber problem
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Problem statement== Imagine a hypothetical barbershop with one barber, one barber chair, and a waiting room with ''n'' chairs (''n'' may be 0) for waiting customers. The following rules apply:<ref>{{cite book |author1=Andrew S. Tanenbaum |author1-link=Andrew S. Tanenbaum |title=Modern Operating Systems |date=2001 |publisher=Pearson |location=Upper Saddle River, NJ |isbn=9780130313584 |page=129 |edition=2nd |url=http://www.microlinkcolleges.net/elib/files/undergraduate/Management/MODERN%20%20OPERATINGSYSTEMSSECOND%20EDITIONby%20Andrew%20S.%20Tanenbaum.pdf |access-date=8 January 2022 |archive-date=8 January 2022 |archive-url=https://web.archive.org/web/20220108235906/http://www.microlinkcolleges.net/elib/files/undergraduate/Management/MODERN%20%20OPERATINGSYSTEMSSECOND%20EDITIONby%20Andrew%20S.%20Tanenbaum.pdf |url-status=dead }}</ref> * If there are no customers, the barber falls asleep in the chair * A customer must wake the barber if he is asleep * If a customer arrives while the barber is working, the customer leaves if all chairs are occupied and sits in an empty chair if it's available * When the barber finishes a haircut, he inspects the waiting room to see if there are any waiting customers and falls asleep if there are none<ref name="ewd">{{cite book |author1=Edsger W. Dijkstra |author1-link=Edsger W. Dijkstra |title=Technical Report EWD-123: Cooperating Sequential Processes |date=1965 |publisher=Eindhoven University of Technology |location=Eindhoven, The Netherlands |page=38 |url=https://www.cs.utexas.edu/users/EWD/transcriptions/EWD01xx/EWD123.html |access-date=8 January 2022}}</ref><ref>[http://www.cs.utexas.edu/users/EWD/transcriptions/EWD01xx/EWD123.html ''Cooperating Sequential processes''] by E.W. Dijkstra. Technical Report EWD-123, 1965, Eindhoven University of Technology, The Netherlands.</ref> There are two main complications. First, there is a risk that a [[race condition]], where the barber sleeps while a customer waits for the barber to get them for a haircut, arises because all of the actions—checking the waiting room, entering the shop, taking a waiting room chair—take a certain amount of time. Specifically, a customer may arrive to find the barber cutting hair so they return to the waiting room to take a seat but while walking back to the waiting room the barber finishes the haircut and goes to the waiting room, which he finds empty (because the customer walks slowly or went to the restroom) and thus goes to sleep in the barber chair. Second, another problem may occur when two customers arrive at the same time when there is only one empty seat in the waiting room and both try to sit in the single chair; only the first person to get to the chair will be able to sit. A ''multiple sleeping barbers problem'' has the additional complexity of coordinating several barbers among the waiting customers.<ref>{{cite web |last1=Fukuda |first1=Munehiro |title=Program 2: The Sleeping-Barbers Problem |url=http://courses.washington.edu/css503/prog/prog2.pdf |website=University of Washington |access-date=8 January 2022}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)