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.
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
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).
- Put your name in the header comments of your dining_philosophers.c. This is very important to me when I am grading the code.
- Comment your code! Part of your grade is dependent upon the presence of useful comments.
- If you cannot get the solution to work, contact me for help. I am available!