From 4c5da634adee509292ae2a41607e592fc5785bfe Mon Sep 17 00:00:00 2001 From: Shikhar Bhushan Date: Sun, 21 Oct 2012 01:21:36 +0530 Subject: [PATCH] don't do a looped cond.await(timeout, unit) as that handles spurious wakeups, and it'll be buggy if the wakeup is due to a call to clear() --- src/main/java/net/schmizz/concurrent/Promise.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/schmizz/concurrent/Promise.java b/src/main/java/net/schmizz/concurrent/Promise.java index 1f6b6154..b3c452fb 100644 --- a/src/main/java/net/schmizz/concurrent/Promise.java +++ b/src/main/java/net/schmizz/concurrent/Promise.java @@ -162,11 +162,14 @@ public class Promise { if (val != null) return val; log.debug("Awaiting <<{}>>", name); - while (val == null && pendingEx == null) - if (timeout == 0) + if (timeout == 0) { + while (val == null && pendingEx == null) { cond.await(); - else if (!cond.await(timeout, unit)) + } + } else { + if (!cond.await(timeout, unit)) return null; + } if (pendingEx != null) { log.error("<<{}>> woke to: {}", name, pendingEx.toString()); throw pendingEx;