[Openmcl-devel] 3 questions - TLS the default? global thread-shared vars? .CDB gen broken?

David L. Rager ragerdl at gmail.com
Sat Mar 19 00:51:48 PDT 2011


Hi Jason,

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
following:

(defun foo ()
; maybe rebinding *myvar* in foo would be a cleaner solution
  (incf *myvar*)
  (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.

David



More information about the Openmcl-devel mailing list