In this assignment you are asked to run some experiments. Do this on at least two systems, say under Solaris and Linux. You can use Mac OSX for one of the systems if you have access to it. When writing up this assignment, be sure to indicate what hardware and OS you used. Be sure to state the clock rate of the CPU.
Part 1:
Mutexes are not useful if, as in Part 0, they are always free.
Think about the following:
How long does it take to do a mutex lock
followed by a mutex unlock when the mutex is not free?
Don't think about this one too long.
Suppose that multiple threads
are incrementing a shared integer.
First determine how fast a given thread can increment an integer in a loop.
Now try this with 10 threads attempting to increment the same shared
integer. Compare the throughput with 10 threads and the throughput with
one thread. For this first experiment we are not doing any synchronization
so the incrementing may not be done correctly. However, you should try to
make sure that all of the threads are active concurrently.
Now protect the shared integer with a mutex. How does this affect the throughput? What happens to the throughput when there are 100 threads?
Part 2:
Are mutexes fair? That is, if 10 threads are incrementing a shared integer
protected by a mutex, in what order do they do their work? Can one thread
increment the integer many times before another thread get in? Design an
experiment to test this. You may have to do more than just increment an
integer in the mutex in order to keep track of which thread is doing the work.
Think about the following: How did you make sure that all of the
threads have started before keeping track of which thread gains the lock?
Parts 3-5:
Pick one of the following that is supported on the two systems you used for
Parts 0-2 and redo these parts using this other synchronization method.
Part 6:
Find out about advisory record locking using fcntl or flock.
This material is not in USP. Possible sources:
Handing in the assignment
You do not need a cover sheet. Hand in your source code along with
a discussion describing the tests you did and comparing the results on
your test systems. Include output when it will be helpful.
Make sure you clearly label the different parts of the assignment.