SBCL multithreaded streams are written to standard output

I wrote a server that spins new threads. Some of these streams should be written to standard output, but when they do this, nothing is displayed in the terminal.

Is there any type of api message in sbcl that allows me to send messages back to the main thread?

Thanks a lot!

+5
source share
1 answer

You need to pass the current *standard-output* to the new stream somehow, and then in this stream function you can bind *standard-output* to this value.

Current common Lisp implementations create streaming 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 name the argument to the stream function *standard-output* , and then I would not need let , since the dynamic binding was done while writing the function. But I think that dynamic bindings should be explicit and obvious, despite the fact that it has special naming conventions.

+10
source

Source: https://habr.com/ru/post/1207851/


All Articles