CSCI 380 -- Lab 5

Barber's Gotta Sleep

Due: Sunday, November 25 @ 11:59 PM

Handout

Skeleton code barber.c can be acquired here: barber.c

Objectives

Problem Description

There 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.

Testing

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>

The program will report a log of events.

Submission

Upload/submit barber.c file to autolab.

Grading Criteria

This lab will be graded out of 80 points.