Barber shop program c


















GetNextCustomer to get an available customer. Customer BarberShop This is where all the business logic resides. The NeedsHaircut routine adds a customer to the end of the queue of waiting customers if the queue has empty spaces. If not, it simply ignores the request. If the queue was empty before adding, then it means that the barber thread was waiting on the event and it releases the event after adding the customer.

Simply derive your class from this class after overriding the virtual run method and then call the Start routine. The entire solution is in 2 files. File: BarberShopSimulation. GetNextCusomer aCust ; if! I keep getting the error saying fatal error: window.

Purpose In this program, we extend the original so-called sleeping-barber problem to a multiple sleeping barbers problem where many customers visit a barbershop and receive a haircut service. For this example of concurrency we make use of the C language and the pthreads thread handling library, in addition to the semaphore library. In the beginning of the program, the barber is sleeping and there are no customers in the shop.

The haircut is to be simulated with a thread sleep of N seconds, where N is a random number between 1. I am having a problem in the synchronisation of threads. I m trying to implement sleeping barber problem in a different approach. When i run the code the threads run in a completely vague manner. When i add join to the threads the processes run one by one which is not required. You are commenting using your WordPress. You are commenting using your Google account.

Barber shop consists of a waiting room with 'n' chairs, and a barber room with one barber chair, 1. If a customer enters the barber shop and all the chairs are occupied then customer leaves shop. If barber is busy but chairs are available then customer sits in one of the free chairs.

If barber is asleep the customer wakes up barber. This simulation uses counter method instead of timer. If he is free the value is set to false. IsRandEven : This variable is used in triggering new customer arrival.

This variable is set to true if the random no. The logic behind is: I am generating random numbers. If the number is even then it triggers a new customer is arrived. If the number is odd, no new customer. Barber is said to be done hair cut if the HairCut static variable reaches the value 5. It is been incremented in the while loop. This replaces the timer method.



0コメント

  • 1000 / 1000