I wrote a server that spins off new threads. Some of those threads need to write to standard-output, but when they do, nothing shows up in terminal.
Is there some type of messaging api in sbcl that allows me to send messages back to the main thread?
Thanks much!
You need to pass the current *standard-output*
to the new thread somehow, then in that thread's function, you can bind *standard-output*
to that value.
Current Common Lisp implementations make thread-local dynamic bindings, and SBCL is one of them.
(sb-thread:make-thread ;; thread function
#'(lambda (standard-output)
;; thread-local dynamic binding of special variable
(let ((*standard-output* standard-output))
...))
;; thread function argument, provided by the current thread
:arguments (list *standard-output*))
Note that I could have named the thread function's argument *standard-output*
and then I wouldn't need the let
, since the dynamic binding was done at function entry. But I think that dynamic bindings should be explicit and obvious, notwithstanding the earmuffs around special variable naming convention.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With