別のスレッドからの継続を中止する方法はありますか?のように:
#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)