From 415a65f88e23410b4f4f1656fc4348913cc271fe Mon Sep 17 00:00:00 2001 From: Nikita Koval Date: Thu, 4 Jul 2019 18:16:58 +0300 Subject: [PATCH] Synchronize threads in `StressStrategy` without parking threads --- .../kotlinx/lincheck/strategy/stress/StressStrategy.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lincheck/src/main/java/org/jetbrains/kotlinx/lincheck/strategy/stress/StressStrategy.java b/lincheck/src/main/java/org/jetbrains/kotlinx/lincheck/strategy/stress/StressStrategy.java index 41af88618..0288758a4 100644 --- a/lincheck/src/main/java/org/jetbrains/kotlinx/lincheck/strategy/stress/StressStrategy.java +++ b/lincheck/src/main/java/org/jetbrains/kotlinx/lincheck/strategy/stress/StressStrategy.java @@ -33,7 +33,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Random; -import java.util.concurrent.Phaser; +import java.util.concurrent.atomic.AtomicInteger; /** * This strategy @@ -46,6 +46,7 @@ public class StressStrategy extends Strategy { private final Runner runner; private final List waits; + private final AtomicInteger uninitializedThreads = new AtomicInteger(0); // for threads synchronization public StressStrategy(Class testClass, ExecutionScenario scenario, Verifier verifier, StressCTestConfiguration testCfg, Reporter reporter) @@ -60,12 +61,12 @@ public StressStrategy(Class testClass, ExecutionScenario scenario, } } // Create runner - Phaser phaser = new Phaser(testCfg.threads); runner = new ParallelThreadsRunner(scenario, this, testClass, null) { @Override public void onStart(int iThread) { super.onStart(iThread); - phaser.arriveAndAwaitAdvance(); + uninitializedThreads.decrementAndGet(); // this thread has finished initialization + while (uninitializedThreads.get() != 0) {} // wait for other threads to start } }; } @@ -84,6 +85,7 @@ public void run() throws InterruptedException { } } } + uninitializedThreads.set(scenario.parallelExecution.size()); // reinit synchronization verifyResults(runner.run()); } } finally {