SleepyBarber

Barber's sleeper problem

Sleeping barber: If there are no customers, the barber falls asleep. If the barber's chair is free, a customer can be seen immediately (does not sit in the waiting chair). The customer waits for the barber if there is an empty waiting chair. If there is nowhere to sit, the customer leaves.

Directed study made in Java on the classic barber problem sleeper. Among several solutions that can be implemented for this problem, in this repository the solution is displayed using the concept of threads and the traffic light technique.

The barber's sleeper problem consists of:

The barber shop has:

  • A barber
  • A barber chair
  • Some chairs for clients wait

If the movement is weak (no clients), the barber sits in his chair and sleeps; When a customer arrives in the empty hall, he has to wake the barber; If other clients arrive while the barber is busy, they:

  • Sit in the waiting chair
  • Go away if there is no empty chair

Implementation of the solution

The implementation has a main traffic light that is the abstraction of the barber's chair. Each client waits for his turn, is actually a thread that tries to acquire the traffic light. Whenever a thread releases the traffic light, a new thread acquires such a traffic light, leaving the queue waiting and releasing a vacancy in such a queue.

Contact

E-mail: guilhermebutzenkunz@gmail.com

Connect with me on LinkedIn

Thanks!