Skip to content
Browse files

Added comments

  • Loading branch information...
1 parent c99839f commit c94370199410903b63c34e37b1645b157602e9ac @tprowx committed
Showing with 50 additions and 0 deletions.
  1. +38 −0 Runner.java
  2. +12 −0 ThreadRace.java
View
38 Runner.java
@@ -0,0 +1,38 @@
+public class Runner implements Runnable {
+ private final String name;
+ public Runner(String name) {
+ this.name = name;
+ }
+
+ @Override public void run() {
+ bm1();
+ System.out.println("Thread \"" + name + "\" Finished!");
+ }
+
+ public void bm1() {
+ final int N = 20;
+ int i;
+ int j;
+ short t;
+
+ short vec[] = new short[N];
+
+ // seed with descending order
+
+ for (i = 0; i < N; i++)
+ vec[i] = (short)(N - i);
+
+ // sort into ascending order
+
+ for (i = 0; i < N - 1; i++) {
+ System.out.println("Thread " + name + ": " + i);
+ for (j = i + 1; j < N; j++) {
+ if (vec[i] > vec[j]) {
+ t = vec[i];
+ vec[i] = vec[j];
+ vec[j] = t;
+ }
+ }
+ }
+ }
+}
View
12 ThreadRace.java
@@ -0,0 +1,12 @@
+public class ThreadRace {
+ public static void main(String[] args) {
+ Runnable travis = new Runner("Travis");
+ Runnable chris = new Runner("Chris");
+
+ Thread t1 = new Thread(travis);
+ Thread c1 = new Thread(chris);
+
+ t1.start();
+ c1.start();
+ }
+}

0 comments on commit c943701

Please sign in to comment.
Something went wrong with that request. Please try again.