Computer Science 4721: Project 2

Due: February 28th, 2002, Before 10:15 am

Posponed: March 5th, 2002, Before 10:15 am

Thread Synchronization

Write a program in Java that creates four threads, each thread blocks until it is notified to continue, it will print out a message that contains its identification and a sequence number, that thread will then notify the next thread in the chain. Assuming that the four threads in the chain are called "A", "B", "C", "D", then two cycles of executing all threads will produce:

A 1
B 1
C 1
D 1
A 2
B 2
C 2
D 2
Thread A will be allow to run initially, it will be continued by a notification from thread D. Thus, thread A starts, print its message, notifies thread B, and then waits to be notified to continue. Thread B, prints a message, notifies thread C, and blocks, Finally, thread D runs and prints its message, and notifies thread A. Only one thread is notified at a time.

The main loop in the run method of each thread should contain the following:

    for( int i = 0 ; i < numCycles; i++ ) {
        // block, wait to be notified
	// print a message
	// notify the next thread in the chain
    }

In this part of the project, you should implement three synchronization methods that implement the blocking and notification. The techniques are:

  1. a gateway class that only allows one thread a time to continue
  2. a set of semaphores, each thread pair in the chain shares a semaphore, the semaphores are set up to only allow one thread to continue.
  3. each thread class must implement a block and a continueNext method using the thread's wait and notify methods to perform the synchronization.
The first technique uses one object to synchronization all the threads. The second technique uses a set of semaphores for each thread pair. The third technique requires each thread to implement the synchronization with Java's built-in synchronization methods directly.

Program to sum 1000 files containing 10000 integers in parallel

The files containing the integers can be found in: /users/cs/faculty/rod/project2_data

The sum program is given as input a directory containing 1000 files. Each file contains 10000 integers, each integer is on a separate line. The sum program should produce the total sum of all the integers in all the files with a set of threads. The program should contain the following threads:

The sum program should accept a command line argument that the specifies the number of worker threads. The program should also determine the time taken to sum all the integers.

Deliverables

You should submit the following:

  1. an electronic copy of your project using submit-assignment,
  2. paper copies of the listing of your project. You should use a2ps to produce the program's listing.
  3. tests of the synchronization program with numCyclesset to 10 for each synchronization technique. The test output should be submitted on paper.
  4. You should run the sum program with the number of workers set to 1, 2, 4, 8, and 16. Compare and discuss the times required to perform the calculations. The discussion should be submitted on paper.