Programming Assignment #1

This assignment will ask you to experiment with the critical section problem. You will run your programs on one of University's SGI machines. You will turn in:

a) A report indicating your findings for each problem.

b) Hard-copies of your programs.

c) E-mail all relevant files to your instructor. In each case there must be clearly indicated how to build the executable and how to use it. I highly recommend that your code follows the rules we apply in the Department.

1. For the beginning you will use a small test program you can download compile and run. You can use either the account you have on charlie or your class account on one of the deltas (delta0 through delta7). Since this class is not about parallel processing, we don't really care how many processors (CPUs) are there: right now we are concerned with several processes working on the same shared data. If you want to learn what hardware is available type hinv at the prompt.

a) What is the value SharedCounter would have if the NUMBER_OF_PROCS processes would be strictly serialized (i.e. a new process would start only after the previous one has finished)?

b) Compile the program and run it a few times (ten times would probably be enough). Do you get the answer you expected? Explain.

c) Fix the problem. You will need to read more about the functions available: try for instance man m_lock. Run the new program (call it share_locks.c) to make sure it always prints the same result. The best way to do this is to have the function that updates SharedCounter run some number of times (MAX_TRIES) and make sure the value of SharedCounter is the expected one.

This problem is worth 20 points.

2. The solution to the first problem involved spin-locking synchronization primitives. Create a new version of the program (called share_sema.c) which will use semaphores instead locks. You will need to do some reading (man -k semaphore could be a good starting point).

This problem is worth 30 points.

3. With the experience you have accumulated so far you are now ready to try one of the classical IPC problems.

a) Producer-consumer with two producers and one consumer. Do this if your SSN modulo 5 is 0.

b) Readers-writers with three readers and two writers. Readers have priority. Do this if your SSN modulo 5 is 1.

c) Readers-writers with three readers and two writers. Writers have priority. Do this if your SSN modulo 5 is 2.

d) Dining-philosophers. Do this if your SSN modulo 5 is 3.

e) The sleeping barber problem with five waiting chairs and a single barber. Do this if your SSS modulo 5 is 4.

Use semaphores in your solution(s). The program should print some meaningful messages indicating what's going on.

This problem is worth 50 points.

Maximum mark: 100 points (100%)