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:
Include everything in a tarred compressed file. Label the file using the following convention: <Lastname>_Assignment1.tar.gz. Email the tarred file to me (laks[AT]cs.uga.edu). Please make the title of the email as “DCS-2007: Assignment-2 – <Your last name>”.
April 20th 2007, 11:59 PM EST
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: