In this first (intentionally simple) assignment, you will use a Java ReentrantReadWriteLock to implement a subset of the java.util.concurrent.atomic.AtomicLong class, which we call SimpleAtomicLock. The goal is to understand how to use ReentrantReadWriteLock to serialize access to a variable that's shared by multiple threads. The SimpleAtomicLongTest.java program creates two Threads that increment and decrement the AtomicLong 10,000,000 times each. If the SimpleAtomicLong implementation is properly serialized it's final value should be 0.
The BuggyLongTest.java program shows what happens if concurrent access to a long isn't properly serialized. This test program works best on a multi-core/multi-processor machine, which should actually induce failure due to race conditions stemming from parallel execution. If this test "succeeds" then your target platform is not sufficiently parallel to demonstrate the bug.
In this directory you'll find the SimpleAtomicLong.java class, which contains the skeleton Java code that you'll implement by completing the "TODO - You fill in here" comments to provide a working solution. DO NOT CHANGE THE OVERALL STRUCTURE OF THE SKELETON - just fill in the "TODO - You fill in here" portions!!!
In particular, you'll need to do the following:
. Implement the SimpleAtomicLong class using a Java ReentrantReadWriteLock, which is covered in this video:
Section 1: Module 2: Part 6: Java ReentrantReadWriteLock
There's also a good tutorial on ReentrantReadWriteLock at
When the 2014 POSA MOOC officially starts these videos will be available at
https://class.coursera.org/posa-002/lecture
We'll also discuss this assignment specification (and later its solution) in the POSA MOOC "Virtual Office Hours", which are described in item #38 at the POSA MOOC FAQ available from
http://www.courera.org/course/posa
To compile this code you can either use the provided Eclipse project or simply type