Skip to content

Commit

Permalink
[GR-11448] Better synchronize to assure that InspectorTester finishes…
Browse files Browse the repository at this point in the history
… properly.
  • Loading branch information
entlicher committed Aug 28, 2018
1 parent 812c8bc commit 8831861
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public Throwable finishErr() throws InterruptedException {
}

private Throwable finish(boolean expectError) throws InterruptedException {
synchronized (exec) {
synchronized (exec.lock) {
exec.done = true;
exec.catchError = expectError;
exec.notifyAll();
exec.lock.notifyAll();
}
exec.join();
RemoteObject.resetIDs();
Expand Down Expand Up @@ -209,6 +209,7 @@ private static class InspectExecThread extends Thread implements InspectServerSe
private final Semaphore initialized = new Semaphore(0);
private boolean catchError;
private Throwable error;
final Object lock = new Object();

InspectExecThread(boolean suspend, final boolean inspectInternal, final boolean inspectInitialization) {
super("Inspector Executor");
Expand All @@ -233,7 +234,7 @@ public void run() {
Source source = null;
CompletableFuture<Value> valueFuture = null;
do {
synchronized (this) {
synchronized (lock) {
if (evalSource != null) {
source = evalSource;
valueFuture = evalValue;
Expand All @@ -242,9 +243,11 @@ public void run() {
} else {
source = null;
valueFuture = null;
try {
wait();
} catch (InterruptedException ex) {
if (!done) {
try {
lock.wait();
} catch (InterruptedException ex) {
}
}
}
}
Expand All @@ -268,10 +271,10 @@ public void run() {

private Future<Value> eval(Source source) {
Future<Value> valueFuture;
synchronized (this) {
synchronized (lock) {
evalSource = source;
valueFuture = evalValue = new CompletableFuture<>();
notifyAll();
lock.notifyAll();
}
return valueFuture;
}
Expand Down

0 comments on commit 8831861

Please sign in to comment.