anchor.diff:          (slow-status-status %status)
           %status)))
   
  +(defun convert-to-slow-status (future stopping-conditions)
  +  (let (slow)
  +    (loop
  +      (let ((%status (future-%status future)))
  +        (when (slow-status-p %status)
  +          (return))
  +        (when (member %status stopping-conditions)
  +          (return %status))
  +        (unless slow
  +          (setf slow (make-slow-status)))
  +        (setf (slow-status-status slow) %status)
  +        (when (eql (cas (future-%status future) %status slow)
  +                   %status)
  +          (return))))))
  +
   (defun wait (future &rest stopping-conditions)
     (declare (dynamic-extent stopping-conditions))
  -  (loop
  -    (let ((%status (future-%status future)))
  -      (when (slow-status-p %status)
  -        (return))
  -      (when (member %status stopping-conditions)
  -        (return-from wait %status))
  -      (let ((new-status (make-slow-status %status)))
  -        (when (eql (compare-and-swap (future-%status future)
  -                                     %status new-status)
  -                   %status)
  -          (return)))))
  +  (let ((status (convert-to-slow-status future stopping-conditions)))
  +    (when status (return-from wait status)))
     (let* ((slow-status (future-%status future))
            (lock        (slow-status-lock slow-status))
            (cvar        (slow-status-cvar slow-status)))
  
positive.code: (defstruct (future
              (:include work-stack:bulk-task)
              (:constructor nil))
    (antideps     nil :type (or list (member :done :cancelled)))
    (waitcount      0 :type word)
    (%status  :frozen :type (or status slow-status)))
  
  (defun dependents (future)
    (let ((antideps (future-antideps future)))
      (and (listp antideps)
           antideps)))
  
  (defun status (future)
    (declare (type future future))
  
negative.code: (defpackage "FUTURE"
    (:use "CL" "SB-EXT" "SB-THREAD")
    (:export "FUTURE"
             "DEPENDENTS"
             "STATUS" "WAIT" "CANCEL"
             "MARK-DEPENDENCIES" "MARK-DONE" "THAW"))
  
  ;;; Infrastructure for futures: lenient-evaluated values
  ;;;
  ;;; A future is a computation with a set of dependencies; whenever
  ;;; all the dependencies for a computation have been fully executed,
  ;;; it too is executed.
  ;;;
  ;;; In order to do so, each future also tracks its antidependencies
  ;;; in list of weak pointers.  When the future is marked as done, the
  ;;; depcount (number of yet unfulfilled dependencies) of its
  ;;; antidependencies is decremented.  When all the dependencies are
  ;;; fullfilled (depcount is zero), the future is recursively executed.
  ;;;
  ;;; For convenience, futures are also bulk-tasks, but this is irrelevant
  ;;; to the interface.
  ;;;
  ;;; Slots in a FUTURE:
  ;;;  function: list designator of functions to be called on execution;
  ;;;            they receive the future as their single argument.
  ;;;  dependents: list of weak pointers to antidependencies, initialized
  ;;;              to zero and updated on demand.
  ;;;  dependencies: vector of dependencies
  ;;;  depcount: number of dependencies yet to be fullfilled, updated on
  ;;;            demand.
  ;;;  %status: current status of the future.  Upgraded to a slow, lock-ful
  ;;;           representation as needed.
  ;;;
  ;;; A future goes through a few stages:
  ;;;
  ;;;  :orphan is the initial stage.  The future is initialized, but not
  ;;;     yet linked to its dependencies.
  ;;;  :frozen futures have been linked to their dependencies (via
  ;;;    MARK-DEPENDENCIES), but not been marked for execution.
  ;;;  :waiting futures have been marked for execution (via THAW),
  ;;;    and will wait until all their dependencies are satisfied.
  ;;;  :running futures have had all their dependencies satisfied
  ;;;  :done futures have finished executing
  ;;;  :cancelled futures have been cancalled
  ;;;
  ;;; STATUS and WAIT can be used to poll a future's current status or wait
  ;;;  until it becomes equal to a value in a set of status.
  ;;;
  ;;; CANCEL marks a future as cancelled, unless it is already executing.
  ;;;
  ;;; Creating a future should follow this pattern:
  ;;;  - Allocate a future
  ;;;  - MARK-DEPENDENCIES
  ;;;  - Maybe walk its DEPENDENTS list for analyses
  ;;;  - THAW it
  ;;;  - Maybe WAIT until :cancelled or :done
  
  (in-package "FUTURE")
  
  (deftype status ()
    '(member :orphan :frozen :waiting :running :done :cancelled))
  
  (defstruct (slow-status
              (:constructor
                  make-slow-status (&optional (status :orphan))))
    (status :orphan          :type status)
    (lock   (make-mutex)     :type mutex
                             :read-only t)
    (cvar   (make-waitqueue) :type waitqueue
  