Subject: Re: Implementation of LET with special variables
From: rpw3@rpw3.org (Rob Warnock)
Date: Wed, 02 Jun 2004 05:30:26 -0500
Newsgroups: comp.lang.lisp
Message-ID: <hLqdneHgU8jfMSDdRVn-jg@speakeasy.net>
Pascal Costanza  <costanza@web.de> wrote:
+---------------
| Ari Johnson wrote:
| > Please explain how it was incorrect, if you have the time.  Thanks. :)
| 
| He already did. When you change the value of a global variable via setq, 
| all threads will see the new value.
+---------------

Well, close, but... That's only correct if the global variable has not
yet been dynamically bound in the current thread. If the global variable
*has* been dynamically bound in the current thread, then a SETQ of the
global variable from within that thread will only change the value seen
within that thread.

Conversely, if the global variable *has* been dynamically bound in the
current thread, say, thread "X", then a SETQ of the global variable from
within some other thread when *not* bound will only change the value
seen within that and other threads in which it hasn't been bound, but
*not* the value seen within "X" and other threads in which *has* been
bound.

This is why (in threaded implementations) you'll often see functions
that start off with:

	(let ((*foo* *foo*)
	      (*bar* *bar*)
	      ...)
	  ;; *FOO* and *BAR* are now protected from SETQs in other
	  ;;  threads, and vice versa.
	  ...
	   ...
	    ...)


-Rob

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607