(Latest Revision: 11/03/2008)
CS 3750 Second Concurrent Programming Assignment
Protocol Execution
If you wish, you may work on this assignment in a team of two persons.
Step 1
Read the file
conc.strp.cpp.
It shows how you can spawn threads and use semaphores to synchronize their
activities. The file also illustrates the use of a random number generator.
After studying
conc.strp.cpp
examine
conc.cpp.
This file is functionally nearly identical to
conc.strp.cpp
The differences are firstly that
conc.cpp.
is set up to write many messages to the screen, secondly that
conc.cpp.
has some code containing extra calls to sched_yield() that are used
to delay threads, and thirdly that
conc.cpp.
has (commented-out) code that changes an operation that may be implemented
atomically into one that will not be atomic (unless the compiler is too
"determined to optimize").
These things are examples of useful ways to test the code.
The messages provide a sort of "play-by-play" commentary that allows the
programmer to run the program and then figure out what each thread did, and
(importantly) when it did something, relative to the time lines of the
other threads.
The other coding variations affect timing characteristics thus helping to
search for latent, time-sensitive errors. The idea is to alter the relative
speeds of threads, and see if that causes the program to produce incorrect
results.
Optional Reading
If you wish, after looking at
conc.cpp,
you could examine
sem.h
and
sem.cpp,
which implement counting semaphores that behave precisely according to the
specifications for counting semaphores in your text book.
If you want more information about pthreads, look at the directions in
pthread_info.html
There is also some information about pthreads in our text book, and you can
consult
this repository of information about a multituude of multithreading
libraries.
Step 2.
By inserting declarations and code into
this header file template, and
this program file template,
create a solution to the concurrent programming
problem described in the problem
description.
For synchronization of concurrent threads, use only the counting
semaphores implemented by
sem.h
and
sem.cpp.
The one exception is that, just as
conc.cpp.
does, you are allowed to use the pthread_mutex_t called
stdoutLock to lock stdout for printing messages.
In particular, you must not add spinlocks or busy-waiting of any
kind.
When I say that the semaphores must be used to do all the "synchronization" of
concurrent threads, I mean any critical section problem or any protocol that
controls the chronological order in which threads interleave their actions.
If that's not sufficiently clear, ask me about it, because your grade will
count heavily on this issue.
Step 3.
E-mail me one
shell archive file
(only one) containing the following items:
- Your version of the protocol.h file - complete with your additions.
- Your version of the protocol.cpp file - complete with your additions.
- One or more script(s) documenting thoughtful, adequate, intelligent
testing
Send the shar file as inline text. Send no attachments. Send the e-mail
before midnight on the due date.
My e-mail address is:
john@ishi.csustan.edu
I will compile and run the program as a part of the grading procedure.
DUE DATE:
For the program due date, see
the class schedule.