;; Simple test of thread cancellation. One thread does something, a second ;; joins on it, and a third cancels the first after you hit enter. If anyone ;; can figure out why evaluating 'a as part of the cleanup of the sleep-proc ;; thread makes Guile crash, by all means let me know (use-modules (ice-9 threads)) (define loop-proc (lambda (i) (begin ((display "Entering thread...") (newline) (newline) (push-thread-cleanup i) (display "counting thread: the counter is ") (display i) (newline) (yield) (sleep 2) (loop-proc (+ i 1)))))) (define sleep-proc (lambda () (begin ((display "Entering thread...") (push-thread-cleanup 'a) (sleep 3000))))) (define joiner (lambda (thread-to-join) (let ((result (join-thread thread-to-join))) (begin (display "joining thread: the counter was ") (display result) (newline))))) ;; Redefine cancelled thread as (make-thread loop-proc 1) to see some different ;; behavior (let ((cancelled-thread (make-thread sleep-proc))) (begin (make-thread joiner cancelled-thread) (read-char (current-input-port)) (display "cancelling thread...") (newline) (cancel-thread cancelled-thread) (newline)))