Thread Safety

Get the Assignment Code

Login to your university Linux account and copy the assignment code to a location under your home directory:

  cp -r /export/home/public/schwesin/cpsc543/assignments/project1 LOCATION

where LOCATION is a directory of your choosing.

The assignment code is also on D2L.

Overview

The goal for this assignment is to make some existing classes thread safe. The following files are in the starter code. The ones through TupleExchange.java require modification. You may need to understand the others. Source files requiring your work contain STUDENT comments in upper case.

Note: Stats.java does not require changes, but it has an example line of code useful in improving FiveTuple.java's thread safety.

Here are some basic guidelines for making this assignment’s classes thread safe:

  1. Make private any data field that can be private.

  2. Inert data containers like TenTuple can have public fields i.f.f. those fields are immutable, for example primitive data types, or references to immutable objects such as String or most (all?) java.lang.Number objects. Mutable objects such as arrays should be private so as not to escape their objects.

  3. Fields should be final when possible. Making a reference to a mutable object final does not make it immutable, but it does guarantee flushing to main memory when the constructor returns. A mutable field should be either volatile, or have every access guarded by an implicit or explicit lock, or have a final reference to a thread-safe object from package java.util.concurrent.atomic We will cover atomic later.

  4. Use the textbook @Immutable, @ThreadSafe, @NotThreadSafe, and @GuardedBy annotations as required in STUDENT comment to communicate design intent.

Perform all test execution on arya to avoid any platform-dependent output differences.

Use make clean test to compile and test your code changes. Testing must occur on arya.

The handout single-main-thread test passes, but the multi-threaded solution won't pass until you complete your work. A successful test does not guarantee that all requirements are met because a race condition that allows tests to pass sometimes is possible. Please re-read all STUDENT requirements before turning it in. When make test does not report an error, testing has succeeded.

  $ cat multi.csv
  Distribution,Param1,Param2,Count,Mean,Median,Mode,Pstdev,Min,Max

The multi-threaded output is missing its data. That is only a header line.

Turning in the Assignment

For this assignment, you must turn in a zip file of a directory named project1 containing your edited files. Submit the zip file to the appropriate folder on D2L.

Dataflow Diagram for this assignment

Dataflow diagram