Due: Sunday, Sept 28 @ 10:00 p.m.
The goal of this exercise is to get you thinking about synchronization problems and to learn a little bit about the synchronization available using pthreads. Since you'll need to use these structures for your malloc implementation, this exercise is directly relevant to your assignment. While you're working, you will need a reference to the pthread libraries. This one from Lawrence Livermore Labs is a good general introduction, and you may wish to read the intro before starting the exercise. You may also want to look at this tutorial about POSIX semaphores.
Please spend no more than 2-3 hours on this exercise! The key goal is to introducing you to synchronization syntax using pthreads so that you can use them in your assignment.
This week's starter code consists of a main program and a list of helper functions that need synchronization. Your first step is to make sure it compiles. On a linux machine, issuing the command "gcc -pthread party.c party_synchro.c" should generate an a.out that you can execute. (Note that the pthread argument is required!) We also provide three short traces for testing your program, though you may want more: under the roomlimit, above the roomlimit, and interactions with the cleaner.
Your goal is to add correct, efficient synchronization to this program. Correct is more important than efficient. Your code will primarily be evaluated on whether it (a) correctly implements the constraints described in party_synchro.c and (b) avoids deadlock or starvation of any thread. If your program is correct, I will time a run on a large simulation and will compare the runtime to other correct solutions.
Hint 0: You should not need to make many changes to party.c. You may need to do some declaration and initialization of synchronization primitives in main. Most of your changes will be in party_synchro.c.
Hint 1: You may notice some similarities between the problem raised in this exercise and the classic readers-writers problem from Monday's lecture.
Hint 2: Busy waiting and unnecessarily large locks will cause performance to suffer.
To complete your exercise, add a "w3exercise" directory to your SVN repository and commit your party.c and party_synchro.c file to that directory. If you are unable to get the simulation working correctly or as efficiently as you'd like, please add a README (text or pdf, please) with a brief description of your approach (and the problems you have encountered).