Getting started

Right click and download this link. This is the skeleton of your lab.


What it will do

A common use for multiple threads is to do something that takes a long time on a second thread, so that the main thread can continue working.

This program supports 3 commands:

This seems like a silly program, but the way it works is exactly how more complex programs work. Once you learn this pattern, you can apply it to many other kinds of problems, like:

Here is an example interaction with the program:

$ ./lab8
> status
	0 alarm(s) pending.
> alarm 5
> alarm 8
> status
	2 alarm(s) pending.
> (RING RING!) status
	1 alarm(s) pending.
> sta(RING RING!)tus
	0 alarm(s) pending.
> alarm 3
> exit
	still 1 alarm(s) pending...
(RING RING!) $

Above, you can see it act kind of funny… the (RING RING!) are the alarms going off. Sometimes, they go off in the middle of the user typing something. Yep! That’s the point! :D


What to do

Compile it like so: gcc -lpthread -Wall -Werror --std=c99 -o lab8 lab8.c

Don’t forget the -lpthread gcc flag!

If you compile and run it right now, it won’t do much. The functions you have to implement are at the bottom. See below for details.

Don’t do everything at once. Implement and test each function below in the order given.


Submission

Please remove all the comments I put in the file before you submit.

Then submit as usual.