[Openmcl-devel] binding with threads

Vijay Mathew vijay.the.lisper at gmail.com
Thu Mar 21 03:41:51 PDT 2013

Consider this code snippet which demonstrates a "futures" package for
executing computations asynchronously:

(setf e (futures:make-pool-executor 2))
(setf f1 (futures:executor-submit e #'(lambda (x) (* x 2)) 100))
(setf f2 (futures:executor-submit e #'(lambda (x y) (+ x y)) 200 300))
(format t "~A~%" (futures:future-result f1))
(format t "~A~%" (futures:future-result f2))
(futures:executor-shutdown e nil)

`pool-executor' internally uses a pool of ccl threads for executing the jobs
submitted to it. Now if I rewrite the same sample using `let' bindings, the
call to `future-result' just hangs. The threads actually run, but it seems
`future-result' somehow do not see the updated value of the internal
`result' slot.

If I load this script, it just hangs the CCL REPL:

(let ((e (futures:make-pool-executor 2)))
  (let ((f1 (futures:executor-submit e #'(lambda (x) (* x 2)) 100))
        (f2 (futures:executor-submit e #'(lambda (x y) (+ x y)) 200 300)))
    (format t "~A~%" (futures:future-result f1))
    (format t "~A~%" (futures:future-result f2))
    (futures:executor-shutdown e nil)))

Also I would like to learn about the best way to debug programs that use
CCL threads.

I am new to Common Lisp and the kind of support I am getting from this
mailing list is very encouraging!

Thank you,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20130321/c5f1bbaf/attachment.htm>

More information about the Openmcl-devel mailing list