C
c++
I need help.
I have to write a pseudocode of this two problems:
- The Sleeping-Barber Problem. A barbershop consists of a waiting room
with n chairs and the barber room containing the barber chair. If there
are no customers to be served, the barber goes to sleep. If a customer
enters the barbershop and all chairs are occupied, then the customer
leaves the shop. If the barber is busy but chairs are available, then
the customer sits in one of the free chairs. If the barber is asleep,
the customer wakes up the barber. Write a program to coordinate the
barber and the customers.
- The Cigarette-Smokers Problem. Consider a system with three smoker
processes and one agent process. Each smoker continuously rolls a
cigarette and then smokes it. But to roll and smoke a cigarette, the
smoker needs three ingredients: tobacco, paper, and matches. One of the
smoker processes has paper, another has tobacco, and the third has
matches. The agent has an infinite supply of all three materials. The
agent places two of the ingredients on the table. The smoker who has
the remaining ingredient then makes and smokes a cigarette, signaling
the agent on completion. The agent then puts out another two of the
three ingredients, and the cycle repeats. Write a program to
synchronize the agent and the smokers.
I have to use the monitor becouse I can't use the semaphore
Thanks
I have to write a pseudocode of this two problems:
- The Sleeping-Barber Problem. A barbershop consists of a waiting room
with n chairs and the barber room containing the barber chair. If there
are no customers to be served, the barber goes to sleep. If a customer
enters the barbershop and all chairs are occupied, then the customer
leaves the shop. If the barber is busy but chairs are available, then
the customer sits in one of the free chairs. If the barber is asleep,
the customer wakes up the barber. Write a program to coordinate the
barber and the customers.
- The Cigarette-Smokers Problem. Consider a system with three smoker
processes and one agent process. Each smoker continuously rolls a
cigarette and then smokes it. But to roll and smoke a cigarette, the
smoker needs three ingredients: tobacco, paper, and matches. One of the
smoker processes has paper, another has tobacco, and the third has
matches. The agent has an infinite supply of all three materials. The
agent places two of the ingredients on the table. The smoker who has
the remaining ingredient then makes and smokes a cigarette, signaling
the agent on completion. The agent then puts out another two of the
three ingredients, and the cycle repeats. Write a program to
synchronize the agent and the smokers.
I have to use the monitor becouse I can't use the semaphore
Thanks