

“In computer science, the sleeping barber problem is a classic inter-process communication and synchronization problem between multiple operating system processes. These 2 semaphores will be used as rendezvous sync to make both customer and barber to arrive end of haircut part together.The Concurrency Explorer (ConcX) provides the tools and features to explore and solve a variety of parallel or asynchronous problems, including the Sleeping Barber problem, described by Wikipedia as follows: The barber waits on customerReady until a customer enters the shop, then the customer waits on barberReady until the barber signals him that it is his turn.Īfter the haircut, the customer signals customerDone and waits on barberDone. customers counts the number of customers in the shop it will be protected by mutex. Limit is the total number of customers that can be in the shop. Mutex = new ReenterantLock() # mutex to protect customer counterĬustomerReady = new Semaphore(0) # barber waits on customerReadyīarberReady = new Semaphore(0) # customer waits on barberReadyĬustomerDone = new Semaphore(0) # customer signals haircut is doneīarberDone = new Semaphore(0) # barber signals haircut is done limit=4 # limit for total number of customer We can use the following variables for synchronisation and mutual exclusion. And we make sure that the given condition is satisfied. So they both signal each other and wait for each other. To provide this guarantee, the following solution is proposed: So they do have a synchronisation to work at a specific parts of their codes at same time. We want to guarantee that a1 happens before b2 and b1 happens before a2.

In other words, given this code Rendezvouses synchronisation Thread A has to wait for Thread B and vice versa.

Barrier works for multiple parties but Rendezvous is done between 2 threads. Rendezvouses: It is a special barrier type. Our solution will use Rendezvous pattern. Our goal is to provide coordination between customers and the barber by complying the above constraints. We need to write a program simulating the barbershop.

Problem DefinitionĪ barbershop consist of a waiting room with n chairs, and a barber room with one barber chair. The original problem was proposed by Edsger Dijkstra. Sleeping Barber problem is another classical concurrency example used in operating system lectures.
