Threads and packages in Common Lisp
The Common Lisp standard doesn’t address threads and other SMP related features. These are provided as custom extensions by several lisp implementation, and while there are libraries that offer a common interface to them, some details are not clearly defined. For example, which package will the reader use in a new thread ? In other words, given the following code snipped
(defpackage :test)
(in-package :test)
(use-package :cl)
(defvar thread-package)
(defun which-package ()
(setf thread-package (symbol-package (read-from-string "test"))))
(bordeaux-threads:make-thread #'which-package)
Which package do we find in package-found
?
I can think of two reasonable choices, one being CL-USER
and the other being the package from
where the thread was started (in our case, TEST
). In fact the two implementations I tried,
SBCL and CLISP under FreeBSD, both opted for CL-USER
, and I guess that others will behave in a similar way.