The barbershop problem involves difficult synchronizations.  The intent of the project is for you to fully understand those synchronizations, so instead of having you work them out on your own, I have provided you with a Pascal examples of the code as sort of a starter kit.

 

Barbershop 1 has some problems.  For example, assume that three customers enter the shop and eventually block on wait[finished].  Also assume that all three are in the barber chairs and one finishes executing signal[finished].  Does the right customer get freed up at wait[finished]?  It is not guaranteed in barbershop 1, but by passing the customer number to the barber and using it as an array subscript, it is guaranteed in barbershop 2.

 

You can solve this problem in project 2 with arrays, but if you do, the maximum grade you will receive is B.  If you want an A, solve the semaphore array problems with condition variables as follows:

           

The condition signal code adds the customer number to a list.  The condition wait code searches through that list.  If the customer number is not in the list, block on the condition wait.  If the customer number is in the list do not block and remove the customer number from the list.

 

Use the most sensible choices of semaphores, mutexes, or condition variables to implement the remainder of this program.