Talk:Sleeping barber problem

message: I don't get the whole picture - maybe I am not so smart :-}. 
In my thinking, each customer enters, take a sit and call the barber to cut his hair. The barber remember who has called him (the "call" will wake him if necessary) and cut the hairs in this order. I fail to see any race conditions here... :-?. Can someone state the prerequisites of this problem more precisely to show what actions are atomic and what not? (As example, how could it be, that the barber wait *on* an customer while this customer wait *on* the barber?)
:When you say that the barber remembers who has called him, you are already solving the problem using a queue. That is a possible solution. Every problem that can be solved with a message queue can be solved with semaphores/shared memory, and vice versa. The problem we want to solve happens when the barber is cutting someones hair and another customer arrives. The barber must finish cutting hair and the second customer must wait. The barber can't cut both hair at the same time, nor stop one in the middle. Barber and customer must be synchronized. Italo Tasso 14:03, 8 June 2007 (UTC)
replies: text: Mutex and semaphore are the same thing. Mutex or lock usually refers to a binary semaphore, whose value is only one or zero. An illustrative example on semaphores would be keys to a room. On the entrace there is a box with keys. If you want to enter, you must grab a key (P function). When you leave, you drop the key on the box (V function). If there are no keys in the box, you wait (P) until someone else drops a key (V). A mutex would be a box with only one key, so that you have only one person in the room at a time. Check out the page about semaphores here at the wikipedia. Italo Tasso 14:03, 8 June 2007 (UTC)
thread_title: The whole picture

message: Are the semaphore inited to zero? maybe it would be helpfull to show their init in the pseodo code. —The preceding unsigned comment was added by 212.143.92.226 (talk • contribs) .
:I just added the initialization values. Italo Tasso 14:03, 8 June 2007 (UTC)
thread_title: Semaphore

message: I did some changes to the pseudo-code:
* The initialization values for the semaphores were missing.
* I replaced the acquire/release semaphore notation with the more conventional P and V. Acquire/release usually refer to locks or binary semaphores. The customers semaphore is not binary. It must assume values greater than 1 to work properly. It is not clear that releasing it several times will increase its value beyond 1.
* In the customer thread, there was a loop that caused all customers to have their hair cut. This is not how it should be. If there are no free seats, the customer leaves without having his hair cut.
Italo Tasso 12:58, 8 June 2007 (UTC)
thread_title: Code changes

message: Is it just me or the semaphore functions aren't right?
Taken from Semaphore article here on wikipedia :
P(Semaphore s)
{
  wait until s > 0, then s := s-1;
  /* must be atomic once s > 0 is detected */
}
V(Semaphore s)
{
  s := s+1;   /* must be atomic */
}
Well...isn't actually P which waits if nothing is available?
The code says :  V(Customers) //tries to acquire a customer - if none is available he goes to sleep
same here:
V(accessSeats) //at this time he has been awakened - want to modify the number of available seats 
or here :
P(accessSeats) //don't need to lock the chairs anymore 
shouldn't we give the lock back (make it 1) ?
I think they should be swapped and it will be ok.
Or maybe it's just me...  141.85.0.74 22:04, 14 November 2007 (UTC)
thread_title:  Mistakes? 

message: I understand that some customers may not get their haircut if there is not any queue. But how it could possibly result in a deadlock?  —Preceding unsigned comment added by 88.101.76.122 (talk) 03:06, 4 March 2008 (UTC)
thread_title:  Deadlock? 

message: I'm a bit baffled by  - what layout is being imagined here for this to make sense, where the barber overtakes the customer on their way to the waiting room? Are we meant to imagine two adjacent rooms for cutting and waiting, with a long corridor that the customer must traverse between them, and a separate, shorter corridor (or even a door or window) which only the barber can use?
I can't find any description of the setup in sources that matches this, only examples like "A sleepy town contains a small barber shop having two doors and a few chairs. Customers enter through one door and leave through the other door." where it's all framed as being one room. Is this "customer not having arrived yet" aspect original research? --Lord Belbury (talk) 16:37, 4 December 2019 (UTC)
thread_title:  Shop layout