[Openmcl-devel] 3 questions - TLS the default? global thread-shared vars? .CDB gen broken?
David L. Rager
ragerdl at gmail.com
Sat Mar 19 02:51:48 CDT 2011
In my application, to get a thread-local variable in CCL, I do
something like the following. I issue the this in the main thread:
(defvar *myvar* nil)
And then, in the function that I pass to
ccl:process-run-function-name, I rebind *myvar*, similar to the
(defun foo ()
; maybe rebinding *myvar* in foo would be a cleaner solution
(format t "~s~%" *myvar*))
(let ((closure (lambda () (let ((*myvar* 123)) (foo)))))
(ccl:process-run-function "threadname" closure))
Which prints 124. Meanwhile, the main thread's *myvar* still has value 0.
If you don't let bind the defvar'd variable, then it's treated as a
global variable. I think some other def's, e.g. defparameter, could
have the same properties.
More information about the Openmcl-devel