Skip to content
Permalink
Browse files

8241456: ThreadRunner shouldn't use Wicket for threads starting synch…

…ronization

Reviewed-by: dholmes, iignatyev
  • Loading branch information
lmesnik committed Apr 3, 2020
1 parent cf22d44 commit a76f0f78ad12c157e36e68254840262529b704a8
@@ -116,8 +116,8 @@ public Wicket(int count) {
public void waitFor() {
long id = System.currentTimeMillis();

lock.lock();
try {
lock.lock();
++waiters;
if (debugOutput != null) {
debugOutput.printf("Wicket %d %s: waitFor(). There are %d waiters totally now.\n", id, name, waiters);
@@ -172,8 +172,8 @@ public int waitFor(long timeout) {

long id = System.currentTimeMillis();

lock.lock();
try {
lock.lock();
++waiters;
if (debugOutput != null) {
debugOutput.printf("Wicket %d %s: waitFor(). There are %d waiters totally now.\n", id, name, waiters);
@@ -209,8 +209,8 @@ public int waitFor(long timeout) {
*/
public void unlock() {

lock.lock();
try {
lock.lock();
if (count == 0)
throw new IllegalStateException("locks are already open");

@@ -241,8 +241,8 @@ public void unlockAll() {
debugOutput.printf("Wicket %s: unlockAll()\n", name);
}

lock.lock();
try {
lock.lock();
count = 0;
condition.signalAll();
} finally {
@@ -257,8 +257,9 @@ public void unlockAll() {
* @return number of waiters
*/
public int getWaiters() {

lock.lock();
try {
lock.lock();
if (debugOutput != null) {
debugOutput.printf("Wicket %s: getWaiters()\n", name);
}
@@ -22,7 +22,6 @@
*/
package nsk.share.runner;

import nsk.share.Wicket;
import nsk.share.gc.OOMStress;
import nsk.share.log.*;
import nsk.share.test.Stresser;
@@ -45,7 +44,7 @@
private RunParams runParams;
private List<Runnable> runnables = new ArrayList<Runnable>();
private List<ManagedThread> threads = new ArrayList<ManagedThread>();
private Wicket wicket = new Wicket();
private AtomicInteger notStarted;
private AtomicInteger finished;
private boolean started = false;
private boolean successful = true;
@@ -97,7 +96,10 @@ public ManagedThread(ManagedThreadFactory threadFactory, Runnable test, int num)

@Override
public void run() {
wicket.waitFor();
notStarted.decrementAndGet();
while (notStarted.get() != 0) {
Thread.onSpinWait();
}
try {
stresser.start(runParams.getIterations());
while (!this.thread.isInterrupted() && stresser.iteration()) {
@@ -187,6 +189,7 @@ private void prepare() {

private void create() {
int threadCount = runnables.size();
notStarted = new AtomicInteger(threadCount);
finished = new AtomicInteger(threadCount);
ManagedThreadFactory factory = ManagedThreadFactory.createFactory(runParams);
for (int i = 0; i < threadCount; ++i) {
@@ -208,7 +211,6 @@ public void start() {
log.debug("Starting " + t);
t.start();
}
wicket.unlock();
started = true;
}

0 comments on commit a76f0f7

Please sign in to comment.