|
UNIVERSITY OF WISCONSIN-MADISON
Computer Sciences Department
|
|
CS 537
Fall 2012
|
| Barton Miller |
|
Programming Assignment #2
(Due Wednesday, October 24, at 5pm)
|
|
A list
of hints and helps for this assignment
is now available.
It will be updated as I get more questions from the class.
Shared Memory Producer/Consumer Program
The goal of this assignment is to get experience in writing a program
that actually runs in parallel on Linxu using threads (pthreads) and
synchronization.
You will write a program with four threads, structured like:
-
The Reader thread will read from standard input, one line at a time.
Reader will take the each line of the input and pass it to thread
Munch1
though a queue of messages.
-
Munch1 will scan the line and replace each blank character with
an asterisk ("*") character.
It will then pass the line to thread
Munch2
through another queue of messages.
-
Munch2 will scan the line and convert all lower case letters to
upper case (e.g., convert "a" to "A").
It will then pass the line to thread
Writer
though yet another queue of messages.
-
Writer will write the line to standard output.
Synchronization and Communication
The threads will communicate through shared memory using pthreads
synchronization.
Tristan Ravitch
prepared a great
tutorial
from a previous semester on how to use pthreads to create threads and synchronize.
Compiling Your Program
See the thread tutorial for compiling instructions.
Program Details
-
Your program will create four pthread threads.
Details on how to create threads is in Tristan's tutorial.
Note that you will not be using
fork
and
exec.
-
Thread Reader will read in each input line.
If the line is longer than 63 characters, it will truncate it to 63
characters (plus the null byte at the end).
Just throw away (flush to end of line) any extra characters.
-
You will read from stdin and write to stdout.
-
See the manual page entry for the function "index"
to making writing Munch1 easier.
-
See the manual page entries for
"islower" and "toupper"
to making writing Munch2 easier.
(Read these function names as
"is lower" and "to upper".
-
Thread Writer will count the number of lines and print
this number to stdout.
-
You should develop a module that implements a queue of character string buffers.
-
The queue itself will be an array of pointers to strings, with integers that
indicate the head and tail of the list.
-
The maximum size of the buffer array will be defined by a constant (using #define
or const int definition.
This maximum should be set to 10.
-
Buffers will be allocated (using malloc) by the Reader
thread and deallocated (using free) by the Writer thread.
-
Threads should terminate when there is no more input (end of file).
Deliverables
To turn in your programs, copy
all .C and .h files, the Makefile and a README (as for Program 1) into
~cs537-1/handin/your_login/prodcons,
along with your Makefile.
Last modified:
Tue Oct 9 10:05:33 CDT 2012
by
bart