CS 439: Project 2

Synchronization - Recursive/Statistical Locks

Due: Friday, Oct. 12th, 11:59PM

This is an individual project. No teaming is allowed.



Overview

Software tuning for large systems often involves an analysis of lock contention.  For this reason, lock implementations often capture statistical data including the numbers of times the locks were acquired/release, and the duration of time the lock was held.

In addition, some applications with fine-grained locking are easier to write if the Thread owning a lock can acquire the lock any number of times without intervening unlocks (and lose the lock only after unlocking it the same number of times.)
This is particularly useful when already holding a lock for an instance A of an item, and then needing to traverse a list of items that may, itself, include A. If logic requires locking each item on the list, then supporting recursively locking avoids awkward code.


Purpose


Assignment:


Supplies

Of the classes provided, the following are the foundations for your solution:


RecursiveLock

Your solution (student.RecursiveLock) must:

Testing Your Work - JUnit (Eclipse or Makefile)

Project2 was exported from Eclipse, with a build path that included: /usr/share/java/junit.jar

This should work on the CS Linux machines. If not, then you will need to remove this from the build path (to avoid error messages), and set it up as needed for your system.

You can run the JUnit tests individually (or en masse) within Eclipse. Using Eclipse for debugging a failing test will be extremely useful.

You can/should use the provided Makefile (in the root of the project) to test your solution.

There are five make "targets", one for each of the tests (the make target tests will run all them for you.)

  1. one_simple_thread
  2. two_simple_threads
  3. violation
  4. instance_count
  5. chaos

These will run the test, redirecting the output to a file, then, for all tests except chaos, it will diff your captured output with the correct output.

If it runs successfully, you should get an "OK ...test" message from JUnit, and the diff should not report any discrepencies, e.g.:

        $ make violation
        java -cp ./:/usr/share/java/junit.jar:./bin org.junit.runner.JUnitCore cs439.lab2.lock.Test_Violation 2> Test_Violation.output
        JUnit version 4.8.2.
        Time: 0.01
        OK (1 test)   <<<< OK is what you want!
        diff Test_Violation.student  outputs/Test_Violation.output  <<<< and this shouldn't report any differences
        $  

We will be running these same tests to check your implementation.


Files to turn in

  1. RecursiveLock.java (Your completed implementation)
  2. README (provided, but you need to complete)

You need to fill out the README file, including the questions at the bottom.
When you're finished with the project, use the make target:

           make turnin

which will create a tar file of your work (README and student/RecursiveLock.java), and invoke turnin for you.
If you'd like to create the tar file and look it over, you can create it without doing the turnin using:

             make turnin_setup