From d5e34d967cd209098110d0be0b75af002530ef25 Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Tue, 19 May 2015 22:28:15 -0700 Subject: [PATCH] Fix deadlock on join() timeout. This closes #4. --- src/Deferred.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Deferred.java b/src/Deferred.java index 9a02a52..e872e3d 100644 --- a/src/Deferred.java +++ b/src/Deferred.java @@ -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) ((Object) signal_cb)); if (timeout == 0) { // No timeout, we can use a simple loop. @@ -1174,12 +1175,15 @@ 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) { + throw new TimeoutException(this, timeout); + } else if (signal_cb.result instanceof Exception) { throw (Exception) signal_cb.result; } return (T) signal_cb.result;