In the first project you will be asked to implement a user-level threads library with mutual exclusion. More on that later. First, you are going to demonstrate your understanding of the semantics of an existing threads library (pthreads, to be exact) and how to use it.
Download the tarball (.tar.gz file) attached to this webpage and uncompress it
with the command: tar zxvf proj1prelab.tar.gz
Contained within, you will find a source (.c) file and a Makefile. (Although
we're not asking you to modify the Makefile now, this would be a good
opportunity to take a look and make sure you understand how it works, because
you may need to modify Makefiles for later projects.) You can compile the
source file with the command make and clean up the compiler output
with make clean. The program should compile and run correctly on
any CoC Red Hat Enterprise Linux (RHEL) system.
(helsinki.cc.gatech.edu is one such machine that allows remote
logins via ssh.)
The source code provided is a multi-threaded consumer-producer program. That
means producer threads add items (in this case, a character) to a queue, and
consumer threads remove the items from the queue and do something with them (in
this case, print the character to standard output). You will find that it
compiles correctly, but when you run the program there are in fact several
bugs. For this pre-lab, you will be asked to do two things: First, find and fix
the five (5) bugs that have been placed in the source code. Second,
create a README file and answer the questions below (short
answers, one or two sentences each). It may be convenient to make a copy of the
original source file before you modify it, since the questions below include
line numbers.
man
[func name]" (e.g. man pthread_create).
exit() (line 66) and
pthread_exit() (line 80). How will the effect of these two
calls differ when they are executed?pthread_join() (line 77) with the
parameter thread_return. Where does the value stored in
thread_return come from when the
consumer_thread is joined?thread_return come from if
the joined thread terminated by calling pthread_exit
instead of finishing normally?pthread_join() (line 77), what will it
do if the thread being joined (consumer_thread, in this
case) finishes before the main thread reaches the that line of code
(line 77)?pthread_join() on
the threads it created. Could a different thread call
pthread_join() on those threads instead? Could a thread
call pthread_join() on the main thread (assuming it knew
the main thread's thread ID - i.e. pthread_t)?sched_yield() when
there are no items in the queue. Why does it call
sched_yield() instead of just continuing to check the
queue for an item until one arrives?README file including answers to all the above questions.