CS 336: Homework

Homework Assignment 3 (due Thurs Sept. 18)

The goal of this assignment is to give you your first opportunity to program using POSOIX threads. You will write a solution to the dining philosophers problem.

Dining Philosophers

Five philosophers are sitting around a table with 5 chopsticks. There is a bowl of rice in the center of the table. Philosophers alternate between thinking and eating. To eat, they need two chopsticks. All but one philosopher picks up the chopstick to her left and then picks up the chopstick to her right. The remaining philosopher picks up the chopstick to his right and then picks the chopstick to his left.

Coding: Create a hw3 directory with src and bin subdirectories. Download dining_philosophers.c into the src directory and implement the solution described above (and in class). There are copious comments in the code skeleton. Use them to guide your code development. Also, Pthread example code from today's class is available at pthread_example.c.

To compile your code, download the Makefile (again, into the src directory) and type make dining_philosophers on the Terminal command line. To test your code, type ../bin/dining_philosophers. If you need to stop execution of the program, type Ctrl-C on the command line. This should interrupt its execution.

Test your solution thoroughly and then email it to me (i.e. email me your code).