Date: Mon, 02 Dec 1996 14:46:11 GMT
Server: NCSA/1.4.2
Content-type: text/html
The turnin program is now accepting the intermdiate submission for Project 4 and the Java extra credit assignment.
start = (double) start_tp->tv_sec + ((double) start_tp->tv_usec)*(1.0e-6); end = (double) end_tp->tv_sec + ((double) end_tp->tv_usec)*(1.0e-6); elapsed_time = end - start;
Below is my solution for the preemptive minithread system. I implemented spinlocks and had a few extra header files. Notice that if you actually destroy threads in semaphore_destroy, you need a special destroy routine that doesn't actually stop the thread (like the one you use to destroy threads in your minithread system). Look for minithread_destroy and minithread_destroy_internal in minithread.c and synch.c to see the difference.
For the bounded buffer problem, I use three semaphores: empty_s and full_s to synchronize the producers and consumers, and pool_s to manage accesses to the buffer pool. In addition, I provide three command line options that enable the user to choose the number of producers, the number of consumers and the size of the buffer pool (this was not part of the assignment).
For the cigarette problem, I use four semaphores: an array needed, one for each ingredient and empty to indicate that there is nothing on the table. The way to think of this is that each of the three smokers (each has a different ingredient) P's on a semaphore that is signalled when the other two ingredients are there. The agent randomly V's on one of these semaphores. I also provided three command line options that allow you to control the agent. In particular, by default the agent puts ingredients on the table, each with equal probability, i.e., in the limit, each smoker will smoke about the same number of cigarettes. The ratio of smokers smoking is 1:1:1. You can use the command line options to change this ratio (this was not part of the assignment).