[Bordeaux-threads-devel] Bug in binding-default-specials

Gustavo gugamilare at gmail.com
Wed Mar 11 21:36:48 UTC 2009


The remove-duplicates function should receive (:key #'car ) argument, since
it is intended to remove the same variable being bound. Patch attached.

By the way, I was thinking if it could be possible to bind some local
variables (since not all implementations support closures).

(defvar *closure-value-table* (make-hash-table :test #'eq :size 10))

(defmacro make-thread-with-closure ((&rest vars) function
                                    &rest make-thread-args)
  (let ((vars (mapcar #'(lambda (var)
                          (if (atom var) (list var) var))
                      vars))
        (table-code (gensym)))
    `(progn
       (setf (gethash ',table-code *closure-value-table*)
             (list ,@(mapcar #'second vars)))
       (make-thread (lambda ()
                      (destructuring-bind ,(mapcar #'car vars)
                          (gethash ',table-code *closure-value-table*)
                        (remhash ',table-code *closure-value-table*)
                        (funcall ,function))) , at make-thread-args))))

cl-user> (make-thread-with-closure ((a 1) (b 2))
                   (lambda ()
                     (+ a b)))
#<sb-thread:thread "Anonymous" running {1005745721}>
cl-user> *
#<sb-thread:thread "Anonymous" finished values: 3 {1005745721}>
cl-user>

Maybe a lock is needed to access the hash-table since not all
implementations support concurrent table access, but that is the general
idea.

Gustavo.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/bordeaux-threads-devel/attachments/20090311/b2c0d95f/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: application/octet-stream
Size: 11785 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/bordeaux-threads-devel/attachments/20090311/b2c0d95f/attachment.obj>


More information about the bordeaux-threads-devel mailing list