next up previous
Next: Main Parts: Due November Up: Problem Statement Previous: Problem Statement

Introductory Parts: Due October 13th

  1. (10 points) Write a program than does the same as part 2 of project 1, except that you are required use POSIX threads rather than fork'ed processes.

    In addition to the main thread, create two additional threads:

    (So the main thread ends up doing very little, other than settings things up, spawning the two threads, and waiting for them to die.)

    Use shared variables as the means of communication between the threads. (Hint: You don't need pipe.) Also, since the two threads are started at the same time, and the second needs to know when the data from the first is available, some form of synchronization is required. You may do this in one of two ways (your choice):

    Note: You must start both threads before you wait for either of them. You will lose points if you call pthread_join on the first thread before you start the second thread running.
  2. (15 points) Implement two solutions for the bounded-buffer producer/consumer problem.

    Both your implementations should consist of a control program that (i) initializes the buffer and the synchronization variables and (ii) creates and terminates the threads for the producer and the consumer. You only need to have a single producer and a single consumer, but you should code with locks in place so that multiple of each would not cause problems.

    The producer generates a stream of printable characters (either fixed or random) and places them into the buffer; and the consumer pulls the characters out of the buffer one at a time and prints them out. Let the buffer be of size 50. For the general test case, let the producer generate 500 characters and then quit, and devise some way of having the consumer quit once it has consumed the last character. While testing, it's probably useful for to also have the producer print them out, so that you can verify what's happenning.

    Implement this using two different methods:

    1. Using POSIX threads and the synchronization primitives pthread_mutex_t and sem_t. Your code should simply realize the pseudocode from figure 5.17 (page 218) of Stallings.

      Use pthread_mutex_t for mutual exclusion (from the pthread library) and sem_t for minding the buffer size (from the posix4 library).

    2. Use POSIX threads and Peterson's software solution for realizing mutual exclusion. Your code should implement the pseudocode on page 214 of Stallings, and use the Peterson's locking code used in figure 5.6 (page 204).

next up previous
Next: Main Parts: Due November Up: Problem Statement Previous: Problem Statement

Davin Milun
Thu Oct 15 21:21:16 EDT 1998