Assignment – 3: Distributed Producer-Consumer System

In this assignment you will learn about threads and synchronization mechanisms in distributed systems. This assignment requires you to implement the classical producer-consumer problem. The system has a multithreaded server which acts as the centralized co-coordinator. A producer is a client that wakes up periodically and sends a message containing an entity (represented by a unique integer) to the coordinator. Analogously, a consumer is a client that wakes up periodically and requests the server for the next available entity. It receives the entity (integer) from the coordinator, prints it into a file and goes back to sleep. Each producer and consumer will have an integer ID (to be initialized during start-up phase)

The centralized server should be multithreaded. It should maintain a fixed-length FIFO queue (to be implemented as a linked list) to hold the items sent-in by producers. The entities enter the queue through one end of the queue and exit through the other end. On the arrival of a new connection, the coordinator spawns off a new thread for handling the incoming connection.

The data stream from producers will have the format PUT <item number> <producer ID>, and the consumer stream will be of the form GET <consumer ID>.  If the incoming connection is from a producer, the coordinator should accept the new entity and add it on to the queue's tail. If the queue is full, the thread (and hence the corresponding producer) will enter a WAIT state until an empty spot becomes available on the entity queue. If the incoming connection is from a consumer, the central server returns the item at the head of the queue (if queue is not empty). If the queue is empty the thread (and hence the corresponding consumer) waits until an item becomes available. The producers and consumers should generate a log of the items they produced or consumed.

Your implementation should ensure that:

  1. A produced item should be served to only one consumer.
  2. None of the items in the queue would be missed.
  3. No producer or consumer should starve (wait forever).
  4. The program should not deadlock.

This assignment can be either implemented in C, C++ or Java. If developing in C/C++, the centralized server should be implemented using pthreads in Linux environment. Java implementations should also work on Linux platforms. C/C++ implementations will be evaluated for 100 points, whereas Java implementations will be evaluted for 80 points. In other words, the maximum score for Java implementations will be 80 whereas it will be 100 for C/C++ implementations.

 This assignment has to be done individually.

What to Submit:

  1. You will submit the source codes of central server, producers and consumers. You should also include makefiles for compiling the code. You should also include a README stating any assumptions you have made.

 How to Submit:

Include everything in a tarred compressed file. Label the file using the following convention: <Lastname>_Assignment3.tar.gz. Email the tarred file to me (laks[AT]cs.uga.edu). Please make the title of the email as “DCS-2009: Assignment-3 – <Your last name>”. 

Submission Deadline:

April 13th 2009, 11:59 PM EST for Grad Students

April 17th 2009, 11:59 PM EST for Undergrads

Resources:

You can find many good articles on pthreads. There are also some good books on pthreads and multithreaded programming. Here are some good articles available on the web:

  1.  http://yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
  2.  http://www.llnl.gov/computing/tutorials/pthreads