Overview
This assignment builds on Assignment 4. You need to have completed at least
through Part 2 of Assignment 4 to start this assignment.
If you have not completed Part 2 of Assignment 4, please see your instructor for guidance.
In this assignment you will use POSIX threads to speed up the program from Assignment 4.
Please note the following changes posted on November 3:
Part 1
Make a directory, assign5, for this assignment.
Copy your working assign4-1.c into assign5-1.c
and make sure it still runs correctly.
Write the following function:
void testRange(unsigned long long start, unsigned long long end);
that does most of the work for this program, including keeping a count
of bad values and printing the bad values.
Use a global variable for the bad value count.
The testRange function should start by printing out its parameters.
Modify your program so that is uses this function.
Part 2
Copy assign5-1.c into assign5-2.c and
modify testRange so that its prototype is:
void *testRange(void *p):
The parameter will be a pointer to a struc containing two
long long fields: start and end.
Modify your program so that it works with these.
Part 3
Copy assign5-2.c into assign5-3.c and modify it so that
it takes one additional integer command line parameter, the number of threads
to use.
It breaks the range into almost equal parts and has one thread
handle each part.
The main thread then waits for all of the threads to complete.
After they all complete, output the good and bad count values.
For this part we are not worrying about synchronization.
It is possible (but unlikely) for the output of the threads to be
interleaved so that some of the lines are unreadable.
It is also possible for the count values to be become corrupt.
Run your program with 1, 2, 4 and 6 threads.
Save the output. Record the machine, date and time of each run and how long
(in seconds) it took to run.
For each run, calculate the speedup (with respect to one thread).
Can you tell from the result how many cores the CPU has?
Part 4
Copy assign5-3.c into assign5-4.c and modify it to
use synchronization to protect the critical sections of this program.
These include the changing of the counts and the output of the bad values.
Use either POSIX mutexes or POSIX unnamed semaphores.
Write a description of how you did the synchronization.
Part 5: Extra Credit
Do not attempt this part unless you have successfully completed Part 4.
Read Section 13.5.3 of USP.
Copy assign5-4.c into assign5-5.c and
modify it to use the sigwait and the method discussed
in Section 13.5.3 to handle the SIGUSR1 signal.
When the signal is delivered,
print the current values of the bad count on a single line.
Be sure to use the proper synchronization.
Save the output generated by running the program and sending a few signals to
it while it is running.
Write a description of what added synchronizion was needed for this part.
Handing in the assignment
Use this cover sheet for handing in your
assignment. Answer the questions listed on the cover sheet.