Due: Sunday, November 25 @ 11:59 PM
Skeleton code barber.c
can be acquired here: barber.c
sem_t
struct and friendsThere is a hypothetical barber shop with one barber. The barber has one barber's chair in a cutting room and a waiting room containing a number of chairs
in it. When the barber finishes cutting a customer's hair (taking cuttime
units of time), he dismisses the customer and goes to the waiting room to see if there are others waiting. If there are, he brings one of them back to the chair and cuts their hair. If there are none, he returns to the chair and sleeps in it.
Each customer, when they arrive, looks to see what the barber is doing. If the barber is sleeping, the customer wakes him up and sits in the cutting room chair. If the barber is cutting hair, the customer stays in the waiting room. If there is a free chair in the waiting room, the customer sits in it and waits their turn. If there is no free chair, the customer leaves after waiting waittime
units of time.
In this problem, we want to potentially allow for many customers to enter at once, so we specify clients
number of threads. A seed
is provided for reproducible output purposes.
You can compile barber.c
with the following command:
gcc barber.c -Wall -Wextra -Werror -pthread -o barber
This will generate a binary ./barber
which can be run as follows:
./barber <runtime> <clients> <chairs> <cuttime> <waittime> <seed>
runtime
-- total execution time of the programclients
-- number of 'client' threadschairs
-- number of chairs in waiting roomcuttime
-- maximum cut time for barberwaittime
-- maximum wait time for any customerseed
-- random number seed to use (for reproducibilityThe program will report a log of events.
Upload/submit barber.c
file to autolab.
This lab will be graded out of 80 points.
50pt
- Correct implementation30pt
- Writeup (include justification of what you did and why)