forked from douglascraigschmidt/POSA-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
00abff2
commit e487ce8
Showing
10 changed files
with
800 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>W2-A1-SimpleAtomicLong-Grading</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
57 changes: 57 additions & 0 deletions
57
grading-drivers/week-2-assignment-1/Assessment-Description.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Week 2: Programming Assignment 1 Peer Assessment Description | ||
|
||
Due Monday, June 9th, 2014 | ||
|
||
You will be asked to evaluate five other student's projects as well as | ||
do a self assessment of your own project. If you do not assess the | ||
work of others, then you will not pass this assignment. | ||
|
||
As you do your evaluation, please keep an open mind and focus on the | ||
positive. Our goal is not to find every way to deduct points over | ||
small deviations from the requirements or for legitimate differences | ||
in implementation styles, etc. Look for ways to give points when it's | ||
clear that the submitter has given a good faith effort to do the | ||
project, and when it's likely that they've succeeded. | ||
|
||
Review the submitter's source code. Since you did your own project, | ||
you know where the changes should be and you have a good idea of the | ||
kind of method calls and work flows that should be in the submitter's | ||
code. Remember that they may have done things differently than you | ||
did. That's fine. | ||
|
||
Next, get a copy of the grading driver files from | ||
|
||
https://github.com/douglascraigschmidt/POSA-14/tree/master/grading-drivers/week-2-assignment-1 | ||
|
||
and copy the submitter's SimpleAtomicLong.java file into your IDE | ||
(which may have been given a random, odd name by Coursera, so you'll | ||
need to rename it) and store it in the src/edu/vuum/mocca/ directory. | ||
I recommend scanning the submitted code to ensure there are no changes | ||
other than adding the appropriate code as indicated by the "TODO" | ||
comments. A quick way to check for this automatically is to run "diff" | ||
on the original SimpleAtomicLong.java file and the submitted | ||
SimpleAtomicLong.java file to make sure all the changes are as | ||
expected, in the expected places in the code. Then make sure | ||
everything compiles properly in your environment. Note that the | ||
grading drivers are in a different location than the original | ||
skeletons to ensure that all submissions are tested against the | ||
"master" regression tests and minimize the amount of code that comes | ||
from "the wild". | ||
|
||
Once you've reviewed the code against the rubric described below | ||
please try to run it, walking through the steps called out in the | ||
grading video that we'll create in each week's "VIrtual Office Hours" | ||
(see item #38 in the POSA MOOC FAQ at | ||
http://www.coursera.org/course/posa for info on Virtual Office | ||
Hours). I suggest you make a fresh Eclipse workspace when doing this, | ||
so that the submitter's code is isolated and easily distinguishable | ||
from yours. One way you can do that is to select File > Open Workspace | ||
> Browse > New Folder. This will lead to a new, empty Eclipse | ||
workspace. Then you can copy that submitter's SimpleAtomicLong.java | ||
file into this new workspace. Also, it's recommended to run the | ||
submitted code a virtual machine sandbox to further isolate it from | ||
causing harm. | ||
|
||
And again, remember that most everyone is working very hard and | ||
putting in a serious effort. When in doubt, err on the side of giving | ||
too many points, rather than giving too few. |
117 changes: 117 additions & 0 deletions
117
grading-drivers/week-2-assignment-1/src/edu/vuum/mocca/BuggyLongTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package edu.vuum.mocca; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.CyclicBarrier; | ||
|
||
/** | ||
* @class BuggyLongTest | ||
* | ||
* @brief This class shows what happens if concurrent access to a long | ||
* isn't properly serialized. | ||
*/ | ||
class BuggyLongTest | ||
{ | ||
/** | ||
* Number of iterations to run the test. | ||
*/ | ||
static final long mMaxIterations = 100000000; | ||
|
||
/** | ||
* Barrier synchronizer that controls when the two threads start | ||
* running the test. | ||
*/ | ||
static CyclicBarrier mStartBarrier = new CyclicBarrier(2); | ||
|
||
/** | ||
* Barrier synchronizer that controls when the main thread can | ||
* return. | ||
*/ | ||
static CountDownLatch mStopLatch = new CountDownLatch(2); | ||
|
||
/** | ||
* An instance of long that's not protected by a lock. | ||
*/ | ||
static long mCounter = 0; | ||
|
||
/** | ||
* Main entry point method that runs the test. | ||
*/ | ||
public static void main(String[] args) { | ||
try { | ||
System.out.println("Starting BuggyLongTest"); | ||
|
||
/** | ||
* Start a Thread whose Runnable decrements the SimpleAtomicLong | ||
* mMaxIterations number of times. | ||
*/ | ||
new Thread(new Runnable() | ||
{ public void run() { | ||
try | ||
{ | ||
/** | ||
* Wait for both Threads to start running | ||
* before beginning the loop. | ||
*/ | ||
mStartBarrier.await(); | ||
|
||
for (int i = 0; i < mMaxIterations; ++i) | ||
mCounter--; | ||
|
||
/** | ||
* Inform the main thread that we're done. | ||
*/ | ||
mStopLatch.countDown(); | ||
} | ||
catch (Exception e) | ||
{ | ||
System.out.println("problem here"); | ||
} | ||
} | ||
}).start(); | ||
|
||
/** | ||
* Start a Thread whose Runnable increments the SimpleAtomicLong | ||
* mMaxIterations number of times. | ||
*/ | ||
new Thread(new Runnable() | ||
{ public void run() { | ||
try { | ||
/** | ||
* Wait for both Threads to start running | ||
* before beginning the loop. | ||
*/ | ||
mStartBarrier.await(); | ||
|
||
for (int i = 0; i < mMaxIterations; ++i) | ||
mCounter++; | ||
|
||
/** | ||
* Inform the main thread that we're done. | ||
*/ | ||
mStopLatch.countDown(); | ||
} | ||
catch (Exception e) { } | ||
} | ||
}).start(); | ||
|
||
/** | ||
* Barrier synchronizer that waits for both worker threads | ||
* to exit before continuing. | ||
*/ | ||
mStopLatch.await(); | ||
|
||
long result = mCounter; | ||
/** | ||
* Check to ensure the test worked, i.e., mCounter's value | ||
* should be 0. | ||
*/ | ||
if (result == 0) | ||
System.out.println("test worked"); | ||
else | ||
System.out.println("test failed: mCounter = " + result); | ||
|
||
System.out.println("Finishing BuggyLongTest"); | ||
} | ||
catch (Exception e) { } | ||
} | ||
} |
Oops, something went wrong.