From a03efded7b95dae3f77e2fc2e628845d3a25cf61 Mon Sep 17 00:00:00 2001
From: Vladimir Sedach <vsedach@gmail.com>
Date: Sat, 5 Feb 2011 21:20:57 -0500
Subject: [PATCH] Fixed race condition w/multiple threads trying to compute
 same future.

---
 future.lisp      | 2 +-
 make-future.lisp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/future.lisp b/future.lisp
index f79286b..0f7b25b 100644
--- a/future.lisp
+++ b/future.lisp
@@ -53,7 +53,7 @@ computation of the future)."
           (with-lock-held ((lock future))
             (when (%ready-to-yield? future)
               (return-from select future))
-            (when (and (not any-computing?) (computing-thread future))
+            (when (computing-thread future)
               (setf any-computing? t))
             (push (cons select-lock notifier) (wait-list future))))
         (unless any-computing?
diff --git a/make-future.lisp b/make-future.lisp
index e95e34b..7a22f71 100644
--- a/make-future.lisp
+++ b/make-future.lisp
@@ -22,7 +22,7 @@ If lazy, newly created futures are not computed until asked to yield their value
       (flet ((get-future () (or (weak-pointer-value future-ptr) (throw 'task-done nil))))
         (let ((*computing-future* (future-id (get-future))))
           (with-lock-held ((lock (get-future)))
-            (if (%ready-to-yield? (get-future))
+            (if (or (%ready-to-yield? (get-future)) (computing-thread (get-future)))
                 (throw 'task-done nil)
                 (setf (computing-thread (get-future)) (current-thread))))
           (finalize (get-future) (let ((thread (current-thread))
-- 
GitLab