Hey guys,
I've been working on some server code in Gambit. One of my projects
uses TCP-SERVICE-REGISTER! to start a service. The problem with this
is that when I go to run the program, Gambit doesn't wait for all
threads to exit by default, so my program immediately exists. I've
seen people add a (##repl-debug-main) call at the end of the script to
keep the program going, but there are several IO issues with doing
this. I would like to simply:
* Tell Gambit to wait for all threads to exit before exiting OR
* Get the thread for the tcp service and join on it OR
* Write a function which joins on all threads
The third option is a bit mysterious to me. I'm not sure how to get
all threads safely, but here was an attempt. This is pseudo-code
basically. The problem with this code is that threads may exit after
I have put them into my list but before I call join on them.
(define (thread-join-all!)
(let* ((threads
(vector->list
(thread-group->thread-vector
(thread-thread-group (current-thread))))))
(for-each (lambda (el)
(if (not (eq? el (current-thread)))
(thread-join! el)))
threads)))
What would be the best way to join on the threads created by
TCP-SERVICE-REGISTER! ?