I've just added some features for checking the state of threads and interrupting threads.
The "thread-state" procedure returns the state of a thread. The "thread-interrupt!" procedure allows interrupting an active thread:
(thread-state (current-thread))
#<thread-state-active #2 waiting-for: #f timeout: #f>
(define t (thread-start! (make-thread (lambda () (let loop ((n 0))
(thread-sleep! .1) (loop (+ n 1)))))))
(thread-interrupt! t) 123
123 ------------- REPL is now in #<thread #3> ------------- *** INTERRUPTED IN ##thread-sleep!
,b
0 ##thread-sleep! 1 loop (console)@1:68 (thread-sleep! .1) 2 ##thread-start-action!
,1
1 loop (console)@1.68 (thread-sleep! .1) \1> ,e n = 37 loop = (lambda (n) (thread-sleep! .1) (loop (+ n 1))) \1>
When a second argument is given to thread-interrupt!, it is a thunk that will be called in the interrupted thread.
The "top" procedure is similar to the Unix "top" program. It displays the state of the threads in the current thread's thread group and refreshes the display every second. Quite useful for monitoring the activity of a multithreaded server! The REPL can also display the list of threads with the ,st command.
Marc
Afficher les réponses par date