-o sigevents -o threads -e main -s
(define (exit-after-some-control-cs control-cs-needed)
;; This is crucial. Alas, its crucialness (cruciality?) is not
;; clearly pointed out in the scsh manual.
(set-interrupt-handler interrupt/int #f)
(format #t "Hit control-C ~A times to exit.~%"
(spawn (lambda ()
(let loop ((sigevent (most-recent-sigevent)))
(let ((next (next-sigevent sigevent interrupt/int)))
(set! control-cs-needed (- control-cs-needed 1))
(if (zero? control-cs-needed)
(begin (format #t "OK, you can go now.~%")
(format #t "Hit control-C ~A more times, and I'll let you go.~%"
(define (main args)
(format #t "Greetings. I'm the main program.~%")
(let loop ()
(format #t "~A: main program pretending to do something useful.~%"
(format-date "~c ~Z" (date (time))))
;; `sleep' appears *not* to work just like the C library function
;; of the same name: the latter returns immediately if a signal
;; arrives, whereas the former keeps chuggin'. That's exactly
;; what I want; thus I don't (as I'd feared) need to use some form
;; of `select', as I would if this were a C program. Nice!