Skip to content
Snippets Groups Projects
Commit a03efded authored by Vladimir Sedach's avatar Vladimir Sedach
Browse files

Fixed race condition w/multiple threads trying to compute same future.

parent c4016f06
Branches
Tags
No related merge requests found
...@@ -53,7 +53,7 @@ computation of the future)." ...@@ -53,7 +53,7 @@ computation of the future)."
(with-lock-held ((lock future)) (with-lock-held ((lock future))
(when (%ready-to-yield? future) (when (%ready-to-yield? future)
(return-from select future)) (return-from select future))
(when (and (not any-computing?) (computing-thread future)) (when (computing-thread future)
(setf any-computing? t)) (setf any-computing? t))
(push (cons select-lock notifier) (wait-list future)))) (push (cons select-lock notifier) (wait-list future))))
(unless any-computing? (unless any-computing?
......
...@@ -22,7 +22,7 @@ If lazy, newly created futures are not computed until asked to yield their value ...@@ -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)))) (flet ((get-future () (or (weak-pointer-value future-ptr) (throw 'task-done nil))))
(let ((*computing-future* (future-id (get-future)))) (let ((*computing-future* (future-id (get-future))))
(with-lock-held ((lock (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) (throw 'task-done nil)
(setf (computing-thread (get-future)) (current-thread)))) (setf (computing-thread (get-future)) (current-thread))))
(finalize (get-future) (let ((thread (current-thread)) (finalize (get-future) (let ((thread (current-thread))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment