This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: thread local variables


> You have three threads.  Thread a is in a repl.  Threads b and c
> are cooperating on some task, and want to share a binding for 
> (current-output-port).  Thread a should have a different binding
> for (current-output-port).

Assuming:
(define (current-output-port) *current-output-port*)

and that:  (fluid-let ((VAR)) BODY)
is syntactatic sugar for:  (fluid-let ((VAR VAR)) BODY)
(I.e. create a new binding but initialize it to the current value);

you can do:

(future (fluid-let ((*current-output-port*)) (thread-a)))
;; Or: (fluid-let ((*current-output-port*)) (future (thread-a)))
(fluid-let ((*current-output-port*))
  (future (thread-a))
  (future (thread-b)))

	--Per Bothner
Cygnus Solutions     bothner@cygnus.com     http://www.cygnus.com/~bothner