Skip to content

Commit

Permalink
Synchronize threads in StressStrategy without parking threads
Browse files Browse the repository at this point in the history
  • Loading branch information
ndkoval committed Jul 4, 2019
1 parent 779b05f commit 06c2631
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +46,7 @@ public class StressStrategy extends Strategy {
private final Runner runner;

private final List<int[]> waits;
private final AtomicInteger uninitializedThreads = new AtomicInteger(0); // for threads synchronization

public StressStrategy(Class<?> testClass, ExecutionScenario scenario,
Verifier verifier, StressCTestConfiguration testCfg, Reporter reporter)
Expand All @@ -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
}
};
}
Expand All @@ -84,6 +85,7 @@ public void run() throws InterruptedException {
}
}
}
uninitializedThreads.set(scenario.parallelExecution.size()); // reinit synchronization
verifyResults(runner.run());
}
} finally {
Expand Down

0 comments on commit 06c2631

Please sign in to comment.