有没有办法从另一个线程中止延续?如:
#lang racket
(define thd
(thread (λ ()
(call-with-continuation-prompt
(λ ()
(sleep 10)
(printf "Don't print me.\n"))
(default-continuation-prompt-tag))
(printf "Do print me.\n"))))
(magically-abort-another-threads-continuation thd)
我希望不必使用线程控制。作为一个更具描述性的示例,假设我想像这样实现 do-only-while-polite:
#lang racket
(define i-am-polite #t)
(define-syntax-rule (do-only-while-polite body ...)
(call-with-continuation-prompt
(λ ()
(define thd (current-thread))
(define politeness-checker-thd
(thread (λ ()
(let loop ()
(cond
[(not i-am-polite)
(magically-abort-another-threads-continuation thd)]
[else (sleep 0.1)
(loop)])))))
body ...
(thread-kill politeness-checker-thd))
(default-continuation-prompt-tag)))
(thread (λ ()
(do-only-while-polite
(printf "Hello.\n")
(sleep 1)
(printf "How are you doing?")
(sleep 1)
(printf "It's nice to meet you."))
(printf "Bye.")))
(sleep 1)
(set! i-am-polite #f)