Skip to content

Commit

Permalink
Merge pull request #1 from douglascraigschmidt/master
Browse files Browse the repository at this point in the history
asd
  • Loading branch information
madhurhasija committed Jun 16, 2014
2 parents 98cfa93 + 37db743 commit 7278606
Show file tree
Hide file tree
Showing 189 changed files with 6,464 additions and 733 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Import the necessary Java synchronization and scheduling classes.

package edu.vuum.mocca;

import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand All @@ -16,91 +18,63 @@ class SimpleAtomicLong
* The value that's manipulated atomically via the methods.
*/
private long mValue;



/**
* The ReentrantReadWriteLock used to serialize access to mValue.
*/

// TODO -- you fill in here by replacing the null with an
// initialization of ReentrantReadWriteLock.
private ReentrantReadWriteLock mRWLock = null;
// TODO - add the implementation

/**
* Creates a new SimpleAtomicLong with the given initial value.
*/
public SimpleAtomicLong(long initialValue)
{
// TODO -- you fill in here
public SimpleAtomicLong(long initialValue) {
// TODO - you fill in here
}

/**
* @brief Gets the current value.
* @brief Gets the current value
*
* @returns The current value
*/
public long get()
{
long value;

// TODO -- you fill in here

return value;
public long get() {
// TODO - you fill in here
}

/**
* @brief Atomically decrements by one the current value
*
* @returns the updated value
*/
public long decrementAndGet()
{
long value = 0;

// TODO -- you fill in here

return value;
public long decrementAndGet() {
// TODO - you fill in here
}

/**
* @brief Atomically increments by one the current value
*
* @returns the previous value
*/
public long getAndIncrement()
{
long value = 0;

// TODO -- you fill in here

return value;
public long getAndIncrement() {
// TODO - you fill in here
}

/**
* @brief Atomically decrements by one the current value
*
* @returns the previous value
*/
public long getAndDecrement()
{
long value = 0;

// TODO -- you fill in here

return value;
public long getAndDecrement() {
// TODO - you fill in here
}

/**
* @brief Atomically increments by one the current value
*
* @returns the updated value
*/
public long incrementAndGet()
{
long value = 0;

// TODO -- you fill in here

return value;
public long incrementAndGet() {
// TODO - you fill in here
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ public class SimpleAtomicLongMultithreadedTest {
static CountDownLatch mStopLatch;

/**
* An instance of our implementation of SimpleAtomicLong.
* An instance of our implementation of SimpleAtomicLong, which is
* defined as "volatile" to ensure proper visibility of its fields
* after construction.
*/
static SimpleAtomicLong mCounter;
static volatile SimpleAtomicLong mCounter;

/**
* Runnable commands that use the mCounter methods
Expand Down
33 changes: 18 additions & 15 deletions assignments/week-3-assignment-2/Assignment-Description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Released Monday, May 26th, 2014
Due Monday, June 9th, 2014

In this assignment, you will use a Java ReentrantLock and Java
ConditionObject to implement a subset of the Java
Condition to implement a subset of the Java
java.util.concurrent.Semaphore class, which we call SimpleSemaphore.
This assignment also reuses the SimpleAtomicLock you implemented for
This assignment also reuses the SimpleAtomicLong you implemented for
week-2-assignment-1, so make sure it's compiling and running properly
before attempting this assignment!

Expand All @@ -19,28 +19,31 @@ Palantirs if you're not yet a fan of Tolkein's Lord of the Ring's.
The PalantirManagerUnitTest.java program creates three Palantiri and
five Threads (one for each Palantir user) that concurrently attempt to
acquire a Palantir and gaze into it for a certain amount of time. If
the SimpleSemaphore and SimpleAtomicLock are implemented properly the
the SimpleSemaphore and SimpleAtomicLong are implemented properly the
test should succeed without throwing any exceptions, as described
further below.

In this directory you'll find a number of files, all of which you
should read. However, the only two files you need to modify are
SimpleAtomicLong.java and SimpleSemaphore.java, 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!!!
SimpleAtomicLong.java and SimpleSemaphore.java in the
src/edu/vuum/mocca directory, 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, which you should replace with
your solution to week-2-assignment-1, after applying any fixes
suggested by peer graders. This class is only used by the
PalantirManagerUnitTest.java and should not be used by the
SimpleSemaphore implementation.

. Implement the SimpleSemaphore class using a Java ConditionObject and
Java ReentrantLock, which are covered in these videos:
motivated by watching the Virtual Office Hours video of the
instructor's solution(s). This class is only used by the
PalantirManagerUnitTest.java and should not be used in the
SimpleSemaphore implementation itself.

. Implement the SimpleSemaphore class using a Java ConditionObject
(accessed via a Condition) and Java ReentrantLock, which are covered
in these videos:

Section 1: Module 2: Part 5: Java ReentrantLock
Section 1: Module 2: Part 8: Java ConditionObject
Expand Down Expand Up @@ -88,7 +91,7 @@ should disappear!

Right click on the test suite (AllTests.java) or an individual
*_UnitTest.java file in Eclipse and select 'Run As' -> 'JUnit
Test'. When the assignment is complete, 12 of 12 tests should complete
Test'. When the assignment is complete, all the tests should complete
successfully. If a test passes a green-check mark will appear next to
the test in the JUnit view. As long as this JUnit test "passes"
successfully your program will be be consider "correct" for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,80 +18,63 @@ class SimpleAtomicLong
* The value that's manipulated atomically via the methods.
*/
private long mValue;



/**
* The ReentrantReadWriteLock used to serialize access to mValue.
*/
// TODO - replace the null with the appropriate initialization:
private ReentrantReadWriteLock mRWLock = null;
// TODO - add the implementation

/**
* Creates a new SimpleAtomicLong with the given initial value.
*/
public SimpleAtomicLong(long initialValue)
{
long value = 0;
public SimpleAtomicLong(long initialValue) {
// TODO - you fill in here
}

/**
* @brief Gets the current value.
* @brief Gets the current value
*
* @returns The current value
*/
public long get()
{
long value = 0;
// TODO - you fill in here, using a readLock()
return value;
public long get() {
// TODO - you fill in here
}

/**
* @brief Atomically decrements by one the current value
*
* @returns the updated value
*/
public long decrementAndGet()
{
long value = 0;
// TODO - you fill in here, using a writeLock()
return value;
public long decrementAndGet() {
// TODO - you fill in here
}

/**
* @brief Atomically increments by one the current value
*
* @returns the previous value
*/
public long getAndIncrement()
{
long value = 0;
// TODO - you fill in here, using a writeLock()
return value;
public long getAndIncrement() {
// TODO - you fill in here
}

/**
* @brief Atomically decrements by one the current value
*
* @returns the previous value
*/
public long getAndDecrement()
{
long value = 0;
// TODO - you fill in here, using a writeLock()
return value;
public long getAndDecrement() {
// TODO - you fill in here
}

/**
* @brief Atomically increments by one the current value
*
* @returns the updated value
*/
public long incrementAndGet()
{
long value = 0;
// TODO - you fill in here, using a writeLock()
return value;
public long incrementAndGet() {
// TODO - you fill in here
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

/**
* @class SimpleSemaphore
*
*
* @brief This class provides a simple counting semaphore
* implementation using Java a ReentrantLock and a
* ConditionObject. It must implement both "Fair" and
* "NonFair" semaphore semantics, just liked Java Semaphores.
* ConditionObject (which is accessed via a Condition). It must
* implement both "Fair" and "NonFair" semaphore semantics,
* just liked Java Semaphores.
*/
public class SimpleSemaphore {
/**
* Define a ReentrantLock to protect the critical section.
* Define a Lock to protect the critical section.
*/
// TODO - you fill in here

/**
* Define a ConditionObject to wait while the number of
* permits is 0.
* Define a Condition that waits while the number of permits is 0.
*/
// TODO - you fill in here

Expand All @@ -30,44 +30,41 @@ public class SimpleSemaphore {
// TODO - you fill in here. Make sure that this data member will
// ensure its values aren't cached by multiple Threads..

/**
* Constructor initialize the data members.
*/
public SimpleSemaphore (int permits,
boolean fair)
{
// TODO - you fill in here
public SimpleSemaphore(int permits, boolean fair) {
// TODO - you fill in here to initialize the SimpleSemaphore,
// making sure to allow both fair and non-fair Semaphore
// semantics.
}

/**
* Acquire one permit from the semaphore in a manner that can
* be interrupted.
* Acquire one permit from the semaphore in a manner that can be
* interrupted.
*/
public void acquire() throws InterruptedException {
// TODO - you fill in here
// TODO - you fill in here.
}

/**
* Acquire one permit from the semaphore in a manner that
* cannot be interrupted.
* Acquire one permit from the semaphore in a manner that cannot be
* interrupted.
*/
public void acquireUninterruptibly() {
// TODO - you fill in here
// TODO - you fill in here.
}

/**
* Return one permit to the semaphore.
*/
void release() {
// TODO - you fill in here
public void release() {
// TODO - you fill in here.
}

/**
* Return the number of permits available.
*/
public int availablePermits(){
// TODO - you fill in here
return 0; // You will change this value.
public int availablePermits() {
// TODO - you fill in here by changing null to the appropriate
// return value.
return null;
}
}

Loading

0 comments on commit 7278606

Please sign in to comment.