Skip to content

Commit

Permalink
Fix deadlock on join() timeout.
Browse files Browse the repository at this point in the history
This closes #4.
  • Loading branch information
tsuna committed May 20, 2015
1 parent dfc36d8 commit 3552d39
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Deferred.java
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,7 @@ private T doJoin(final boolean interruptible, final long timeout)
try {
while (true) {
try {
boolean timedout = false;
synchronized (signal_cb) {
addBoth((Callback<T, T>) ((Object) signal_cb));
if (timeout == 0) { // No timeout, we can use a simple loop.
Expand Down Expand Up @@ -1174,12 +1175,16 @@ private T doJoin(final boolean interruptible, final long timeout)
// But entering `wait' is pretty much guaranteed to make the
// loop take more than 100ns no matter what.
if (timeleft < 100) {
throw new TimeoutException(this, timeout);
timedout = true;
break;
}
}
}
}
if (signal_cb.result instanceof Exception) {
if (timedout && signal_cb.result == signal_cb) {
// Give up if we timed out *and* we haven't gotten a result yet.
throw new TimeoutException(this, timeout);
} else if (signal_cb.result instanceof Exception) {
throw (Exception) signal_cb.result;
}
return (T) signal_cb.result;
Expand Down

0 comments on commit 3552d39

Please # to comment.