Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spinlock synchronization in parallel threads runner #4

Merged
merged 1 commit into from
Jul 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
ndkoval marked this conversation as resolved.
Show resolved Hide resolved
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