Programming Assignment


This assignment has three parts. The first two parts will expose you to the usage of locks and semaphores in a program written by your instructor. The third part of the assignment will ask you to write a program that solves one of the classical IPC problems.

You will develop and run your programs in a UNIX environment, on one of University's SGI machines.

You will turn in:

  1. A memo indicating your findings for each problem. Direct the memo to your instructor.
  2. Hard-copies of your programs.

In addition you will e-mail all relevant files to your instructor. In each case you must clearly indicate how to build the executable and how to use it. Your code must follow the coding style and documentation standards recommended in the Department.


Part 1

For the beginning you will use a small test program you can download, compile and run. You will use the account you have on charlie. 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 the variable SharedCounter would have if the NUMBER_OF_PROCS processes would run 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 part of the assignment is worth 20 points.


Part 2

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

This part of the assignment is worth 30 points.


Part 3

With the experience you have accumulated so far you are now ready to try one of the classical IPC problems. The problem you have to solve is given by the formula
SSN mod 5 + 1
where SSN is your Social Security Number.
  1. Producer-consumer with two producers and one consumer.
  2. Readers-writers with three readers and two writers. Readers have priority.
  3. Readers-writers with three readers and two writers. Writers have priority.
  4. Dining-philosophers.
  5. The sleeping barber problem with five waiting chairs and a single barber.

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

This part of the assignment is worth 50 points.


Last update: June 8, 1997 The cs450 home page. Virgil Bistriceanu's home page. The Computer Science and Applied Mathematics home page