CS 4210, Spring 2005

Homework 1

Due 5 PM Thursday January 27, 2005

Turn in electronically (email to fujimoto@cc.gatech.edu)

1.     Turn in a digital picture of yourself (head shot).

2.     Write a pthreads program using the producer/consumer (work queue or work pile) model to do some simple arithmetic on numbers entered on the keyboard.  Your program should take a single command line argument that indicates the number of consumer (worker) threads that should be created.  After creating the worker threads, the main program should repeatedly prompt the user and read a number entered from the keyboard.  This number should be placed into a queue.  One of the consumer threads should then remove the number from the queue, compute the square of the number, print the result, and then go back and wait for more work to do.  You may assume the queue size is bounded of some reasonable size (if the queue becomes full, the main thread should block).  You may assume the program executes forever, i.e., the main program and worker threads never exit.

Notes on this assignment:

 

 

Some suggestions in programming with pthreads:

gcc –o prog prog.c –lpthread