--- jsr166/src/test/loops/SimpleNoLockLoops.java 2005/05/02 19:19:38 1.1 +++ jsr166/src/test/loops/SimpleNoLockLoops.java 2009/10/29 23:09:08 1.4 @@ -1,11 +1,7 @@ /* - * @test - * @synopsis multiple threads using a single builtin lock - */ -/* * Written by Doug Lea with assistance from members of JCP JSR-166 - * Expert Group and released to the public domain. Use, modify, and - * redistribute this code in any way without acknowledgement. + * Expert Group and released to the public domain, as explained at + * http://creativecommons.org/licenses/publicdomain */ import java.util.concurrent.*; @@ -20,7 +16,7 @@ public final class SimpleNoLockLoops { public static void main(String[] args) throws Exception { int maxThreads = 100; - if (args.length > 0) + if (args.length > 0) maxThreads = Integer.parseInt(args[0]); new ReentrantLockLoop(1).test(); @@ -35,8 +31,8 @@ public final class SimpleNoLockLoops { if (i == k) { k = i << 1; i = i + (i >>> 1); - } - else + } + else i = k; } pool.shutdown(); @@ -55,7 +51,7 @@ public final class SimpleNoLockLoops { } final void test() throws Exception { - for (int i = 0; i < nthreads; ++i) + for (int i = 0; i < nthreads; ++i) pool.execute(this); barrier.await(); barrier.await(); @@ -74,7 +70,7 @@ public final class SimpleNoLockLoops { public final void run() { try { - barrier.await(); + barrier.await(); int sum = v + 1; int x = 0; int n = iters; @@ -84,7 +80,7 @@ public final class SimpleNoLockLoops { if (k > 0) { x = v; while (k-- > 0) - x = LoopHelpers.compute4(x); + x = LoopHelpers.compute6(x); v = x; } else x = sum + 1; @@ -92,16 +88,15 @@ public final class SimpleNoLockLoops { if ((x += readBarrier) == 0) ++readBarrier; for (int l = x & 1; l > 0; --l) - sum += LoopHelpers.compute4(sum); - } + sum += LoopHelpers.compute6(sum); + } barrier.await(); result += sum; } - catch (Exception ie) { - return; + catch (Exception ie) { + return; } } } } -