Skip to content

Tanmay-312/Sleeping-Barber-GO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Sleeping-Barber-GO

The sleeping barber problem is a hypothetical situation that mirrors real-world concurrency challenges in system design and development. The problem involves a barber shop with one barber, one barber chair, and a waiting room with chairs for the customers. The barber sleeps when there is no customer in the waiting room. When a customer arrives, the barber is woken up and cuts the customer's hair. If there are no empty chairs in the waiting room when a customer arrives, the customer leaves.

The ClientsChan channel is used to communicate between the clients and the barber. The barber process receives a customer from the channel and cuts their hair. If there are no customers in the channel, the barber waits. The customer process sends their id to the channel and waits for the barber to finish cutting their hair.

This solution ensures that the barber is always woken up when a customer arrives and that customers are never left waiting if there are empty chairs in the waiting room.

Here are some additional details about the sleeping barber problem:

  1. The problem is often attributed to Edsger Dijkstra, one of the pioneers in computer science.
  2. The problem is a classical problem of process synchronization.
  3. The problem is not just a theoretical puzzle; it mirrors real-world challenges in system design and development.
  4. The problem can be solved using a variety of different methods, including semaphores, mutexes, and channels.
  5. The problem is a good example of how to use concurrency to solve a real-world problem.