Skip to content

Instantly share code, notes, and snippets.

@dannypsnl
Created February 21, 2025 13:13
Show Gist options
  • Select an option

  • Save dannypsnl/50e0b0aa8c83d70433b639234fa81f1d to your computer and use it in GitHub Desktop.

Select an option

Save dannypsnl/50e0b0aa8c83d70433b639234fa81f1d to your computer and use it in GitHub Desktop.
Get chez scheme stuck
(import (chezscheme))
(define handler-key (gensym))
(define th #f)
(define x 0)
(define (sub)
(define n
(call/cc (lambda (k)
(define abort (continuation-marks-first (current-continuation-marks) handler-key))
(abort k))))
(set! x (+ x n)))
(write x)
(newline)
(with-continuation-mark
handler-key (lambda (resume)
(set! th (fork-thread (lambda () (resume 20))))
(resume 10))
(sub))
(write x)
(newline)
(thread-join th)
@dannypsnl
Copy link
Author

dannypsnl commented Feb 21, 2025

If you resume the current stack from another thread, and also resume it in the current thread: blocked.

More interesting, if you don't do resume in the current thread, but only invoke it from another thread: + will receive a second call with bad arguments:

0
20
Exception in +: #<void> is not a number

Which means (resume) happened 2 times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment