6815130: Intermittent ThreadMXBean/Locks.java test failure

Preventing stale reads from ThreadExecutionSynchronizer.waiting flag

Reviewed-by: dholmes, mchung, dfuchs
This commit is contained in:
Jaroslav Bachorik 2013-09-06 10:03:16 +02:00
parent 37709e3191
commit 61000f0c4b
2 changed files with 14 additions and 15 deletions

View File

@ -193,16 +193,18 @@ public class Locks {
public CheckerThread() {
super("CheckerThread");
}
private void waitForState(Thread.State state) {
thrsync.waitForSignal();
while (waiter.getState() != state) {
goSleep(10);
}
}
public void run() {
synchronized (ready) {
// wait until WaitingThread about to wait for objC
thrsync.waitForSignal();
int retryCount = 0;
while (waiter.getState() != Thread.State.WAITING
&& retryCount++ < 500) {
goSleep(100);
}
waitForState(Thread.State.WAITING);
checkBlockedObject(waiter, objC, null, Thread.State.WAITING);
synchronized (objC) {
@ -211,16 +213,13 @@ public class Locks {
// wait for waiter thread to about to enter
// synchronized object ready.
thrsync.waitForSignal();
// give chance for waiter thread to get blocked on
// object ready.
goSleep(50);
waitForState(Thread.State.BLOCKED);
checkBlockedObject(waiter, ready, this, Thread.State.BLOCKED);
}
// wait for signal from waiting thread that it is about
// wait for objC.
thrsync.waitForSignal();
waitForState(Thread.State.WAITING);
synchronized(objC) {
checkBlockedObject(waiter, objC, Thread.currentThread(), Thread.State.WAITING);
objC.notify();

View File

@ -23,7 +23,7 @@
/*
*
* @summary Thiseclass is used to synchronize execution off two threads.
* @summary This class is used to synchronize execution of two threads.
* @author Swamy Venkataramanappa
*/
@ -31,8 +31,8 @@ import java.util.concurrent.Semaphore;
public class ThreadExecutionSynchronizer {
private boolean waiting;
private Semaphore semaphore;
private volatile boolean waiting;
private final Semaphore semaphore;
public ThreadExecutionSynchronizer() {
semaphore = new Semaphore(1);