Lisp HUG Maillist Archive

per process variable bindings

Is there a LispWorks function or declaration I'm missing that allows a special variable scope to be per process rather than global? The only thing I found is mp:*process-initial-bindings*, but it seems that would add a lot of overhead at the start of the process for a large number of variables to bind. It my case it would be likely only a small number of them would be used in the process, but there is no way to know ahead of time. 

Thanks,

John DeSoi, Ph.D.


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Re: per process variable bindings



On 18 Sep 2019, at 05:00, John DeSoi (as desoi at pgedit dot com) <lisp-hug@lispworks.com> wrote:

Is there a LispWorks function or declaration I'm missing that allows a special variable scope to be per process rather than global? The only thing I found is mp:*process-initial-bindings*, but it seems that would add a lot of overhead at the start of the process for a large number of variables to bind. It my case it would be likely only a small number of them would be used in the process, but there is no way to know ahead of time.

Thanks,

John DeSoi, Ph.D.


I would use (bordeaux-threads:make-thread (function my-thread) :initial-bindings ‘((*my-thread-specific-special* . 42)))

For example, in ccl:


cl-user> (defvar *my-thread-specific-special* 33)
*my-thread-specific-special*
cl-user> (defvar *thread-result* '())
*thread-result*
cl-user> (let ((thread (bt:make-thread (lambda () (loop repeat 3 do  (sleep 1) (print (push *my-thread-specific-special* *thread-result*))))
                                       :initial-bindings '((*my-thread-specific-special* . 42)))))
           (setf *my-thread-specific-special* 0 
                 *thread-result* '())
           (unwind-protect
                (loop repeat 3 do (incf *my-thread-specific-special*) (sleep 1))
                (bt:destroy-thread thread))
           (values *my-thread-specific-special* *thread-result*))
3
(42 42 42)
cl-user> 

I would expect the same in lispworks…

-- 
__Pascal J. Bourguignon__




Re: per process variable bindings

Unable to parse email body. Email id is 15027

Re: per process variable bindings

I'm translating another language to Lisp that has the concept of process variables. They have a type and default value, and may or may not be used in any given process. I toyed around with managing the values in a per process hash table, but I think it will be easier and more consistent to use Lisp variables. In theory there should be a declaration before it is used that would allow me to bind it to the default as needed, but that is not strictly required by the language. 

I'll try mp:*process-initial-bindings* and see where it goes. Thanks for your help.

John DeSoi, Ph.D.


> On Sep 18, 2019, at 8:38 AM, Martin Simmons <martin@lispworks.com> wrote:
> 
> Why do you have a large number of variables and at what point do you know
> which ones need to be bound per process?


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html

Updated at: 2020-12-10 08:29 UTC