Skip to content

Commit

Permalink
Fixed "Lock" to be "Long".
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascraigschmidt committed May 14, 2014
1 parent bec5722 commit 6618744
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions assignments/week-2-assignment-1/Assignment-Description.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Programming Assignment 0
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
SimpleAtomicLong. 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
Expand Down Expand Up @@ -67,11 +67,11 @@ http://www.courera.org/course/posa
To compile this code you can either use the provided Eclipse project
or simply type

% javac SimpleAtomicLockTest.java SimpleAtomicLock.java
% javac SimpleAtomicLongTest.java SimpleAtomicLong.java

on the command-line and then run the resulting class file by typing

% java SimpleAtomicLockTest
% java SimpleAtomicLongTest

The output for a correct solution should look exactly like this:

Expand Down
8 changes: 4 additions & 4 deletions ex/PingPong/console/src/edu/vuum/mocca/PlayPingPong.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static class PingPongThreadCond extends PingPongThread
/**
* Thread whose turn it currently is.
*/
private static long mThreadOwner;
private static long mTurnOwner;

public void setOtherThreadId(long otherThreadId)
{
Expand All @@ -213,7 +213,7 @@ public void setOtherThreadId(long otherThreadId)
mConds[FIRST_COND] = firstCond;
mConds[SECOND_COND] = secondCond;
if (isOwner)
mThreadOwner = this.getId();
mTurnOwner = this.getId();
}

/**
Expand All @@ -222,7 +222,7 @@ public void setOtherThreadId(long otherThreadId)
void acquire() {
mLock.lock();

while (mThreadOwner != this.getId()) {
while (mTurnOwner != this.getId()) {
mConds[FIRST_COND].awaitUninterruptibly();
}

Expand All @@ -238,7 +238,7 @@ void release() {
--mTurnCountDown;

if (mTurnCountDown == 0) {
mThreadOwner = mOtherThreadId;
mTurnOwner = mOtherThreadId;
mTurnCountDown = mMaxTurns;
mConds[SECOND_COND].signal();
}
Expand Down

0 comments on commit 6618744

Please sign in to comment.