Barber Shop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DOA
    New Member
    • Jan 2008
    • 1

    #1

    Barber Shop

    simulation of the sleeping barber problem. The given program first creates a barber thread. The barber thread calls callNext to get a customer, waits a random amount of time (to simulate the time it takes to cut hair), and then repeats the process.
    After the barber thread is created, the program creates customer threads at random intervals. The customer threads call enter to enter the shop and then wait for the barber to complete the haircut (using a barrier for synchronization ).

    Your task is to write code for callNext and enter so the barber sleeps when there are no customers waiting and the customers wait if the barber is busy or leave if the shop is full. BarberShop has instance variables waiting and activity to help you keep track of how many customers are waiting and what the barber is doing, as well as condition variables customers and barber used to synchronize the two types of threads. There is also a mutex called mutex you can use to enforce mutually exclusive access to the instance variables. callNext should

    check for waiting customers
    if there are none, wait
    if there are waiting customers, signal one
    enter should
    check the state of the barber and the number of waiting customers
    wake (signal) the barber if no one else is waiting and the barber is asleep
    leave the shop if the shop is full (or closed)
    wait if the barber is cutting and there is room left in the shop
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Please read the guidelines for asking for help on homework questions.

    Comment

    Working...