Question
Write a C program using threads to perform the following: A barber shop has one barber and one barber chair, therefore only one customer can
Write a C program using threads to perform the following:
A barber shop has one barber and one barber chair, therefore only one customer can enter in order to get a new haircut. If there are no customers present, the barber sits down in the barber chair and falls asleep. When a customer arrives, the customer has to sit on the barber chair to get the haircut so the chair will be taken. If additional customers arrive while the barber is busy (chair was taken), they have to wait outside the shop or leave. The barber can accept 32 customers per day, when this number is reached he will close the shop.
Declare a variable Customer as an integer.
Declare and define 2 functions: Sleep, Haircut.
Define the function Sleep such that Customer will be reset to zero if no customers are available inside the shop.
Define the function Haircut such that Customer will be incremented by one if a customer enters the shop to get a haircut.
Use a Counter to count the total number of customers served by the barber.
The program should be stopped by the user.
The program should create two threads as follows: o Thread 1: Call function Sleep and print the thread ID
o Thread 2: Call function Haircut and print the thread ID Make sure to include messages all over your code whenever a thread is created/joined/exited, the barber sleeps or a customer is having a new haircut.
Set threads default attributes. The barber can accept a maximum of 32 customers per day only. Implement this in your code
using a variable called Limit. After the thread exits, the main program should print the value of the Counter on the screen. Join all threads.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started