Helmut Eller e9626484@stud3.tuwien.ac.at writes:
If the parent thread has a dynamic binding the child will also have a dynamic binding and the value will be inherited from the parent. The dynamic binding itself is private to a thread and SETQ-ing it will not change the value in other threads. Only the global (non-dynamic) binding is shared.
What the ... ?!?!
Creating a thread is probably not very fast, but Common Lisp was not designed with concurrency in mind.
Well I assume most special variables will be "at the global binding", but still...
Here's an example:
(defvar *dvar* 10)
(let ((*dvar* 20) (lock t)) (sb-thread:make-thread (lambda () (print *dvar*) (setq *dvar* 30) (setq lock nil))) (loop while lock do (sleep 0.2)) (print *dvar*))
This prints
20 20
in SBCL. The equivalent (MAKE-THREAD replaced with PROCESS-RUN-FUNCTION) in Allegro prints:
10 20
You're absolutely right. And leaving out the (*dvar* 20) from the LET prints 10 30 for both Lisps.
Quite frankly, I find SBCL's behaviour baffling. Let's see what replies I get to my request for a rationale on sbcl-devel.
Kind regards,
Dirk Gerrits