unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Question about handling SIGINT properly in Guile
@ 2024-04-13 14:46 Vijay Marupudi
  2024-04-13 16:46 ` Olivier Dion
  2024-04-14 23:12 ` Maxime Devos
  0 siblings, 2 replies; 7+ messages in thread
From: Vijay Marupudi @ 2024-04-13 14:46 UTC (permalink / raw)
  To: guile-user

Hello folk of guile-user,

I am trying to create a simple Guile program that continues to perform a
task until an interrupt signal is sent. However, I am unable to
deterministically end the program when SIGINT is sent, as the
interrupt handler does not run soon after the call to (sleep ...) ends.

Try running the simple reproduction included below. Try typing ^C
(Ctrl+C) soon after the program begins. Sometimes "WORK" is run
once, and sometimes "WORK" is run twice. What do I need to do to make
"WORK" run only once in this instance?


(define quit? #f)

(sigaction SIGINT (lambda (arg)
                    (pk "SIG" arg)
                    (set! quit? #t)))

(let loop ()
  (pk "QUIT-CHECK")
  (if quit?
      (begin (format #t "Quitting!~%") (exit 0))
      (begin (pk "WORK" (do ((i 0 (+ i 1))
                             (sum 0 (+ sum i)))
                            ((= i 1000) sum)))
             (pk "SLEEP" (sleep 10))
             (loop))))


I understand that signal handlers are asynchronous (Asyncs) and aren't
guaranteed to run immediately. However, I expect them to be run before
the next primitive call. Am I doing something wrong?

~ Vijay



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-17 14:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-13 14:46 Question about handling SIGINT properly in Guile Vijay Marupudi
2024-04-13 16:46 ` Olivier Dion
2024-04-13 20:22   ` Vijay Marupudi
2024-04-14 22:50     ` Maxime Devos
2024-04-14 23:12 ` Maxime Devos
2024-04-16  0:43   ` Vijay Marupudi
2024-04-17 14:28     ` Vijay Marupudi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).