CS 52500 - Programming Assignment 1

This assignment makes use of the files contained in this zip file (or this zip file for Linux or Mac OS X). This assignment is due Tuesday, September 18. (Note: This is an updated due date.)

In this assignment you will solve three related synchronization problems using the Pthreads library and condition variables.

In the zip file there is a file CS525Hw1.c that should compile and run as is. This demonstrates a "console gui" framework for watching threads run. Every time you strike a key from the keyboard, this program launches a new "customer" thread that goes through three states: being in an "entry area", then being in a "dining area", and finally being in an "exit area". The "gui" gives a visual representation of these thread states. In this demonstration, there is no synchronization between the threads. Your assignment is to implement three different synchronization patterns for the "costumer" threads.

The first synchronization pattern puts a bound on the number of threads that can be in the "dining" state. Once the dining capacity is reached, new threads must block until some other threads leave the dining state.

The second synchronization pattern is to solve the "sushi problem" as described in "The Little Book of Semaphores". There is a bound on the number of threads that can be in the dining state. In addition, once the bound is reached, new threads are blocked from the dining state until all threads in the dining state exit the dining state. At that point, blocked threads can enter the dining state (up to the bound of the dining state). If the bound on the number of threads in the dining state is not reached, then threads can enter the dining state without blocking.

The third synchronization pattern is a variation on the sushi pattern (sometimes called the "art gallery problem"). There is no bound on the number of threads that can be in the dining state. Threads are allowed to enter the dining state only when the number of threads in the dining state goes to zero. At that time, all of the waiting threads (no matter how many there are) are allowed to enter the dining state, and then the dining room is "locked" until the last thread leaves the dining state, and then another group of threads can enter the dining state all together. When the number of threads in the dining state is zero and there is no thread blocked, then the first thread to try to enter the dining state gets in and locks the dining state, so it is in the dining state alone.

In the zip file there are four outlines of the customer thread, customer.h, customerBounded.h, customerSushi.h, and customerArtGallery.h. The header file customer.h is used for the original demonstration (without any synchronization). You do not need to do anything with this file. You should put your implementation of each synchronization pattern in the appropriate header file, choose that header file in CS525Hw1.c, and then compile and run CS525Hw1.c. (If you want, it may be easier to create three copies of CS525Hw1.c, one for each synchronization pattern.)

Turn in a zip file containing your implementations of the customerBounded.h, customerSushi.h, and customerArtgallery.h files, and also all of the other files that are in zip file.

This assignment is due Tuesday, September 18.


Return to the main homework page.
Return to the CS 52500 home page.


compliments and criticisms