unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Vijay Marupudi <vijaymarupudi@gatech.edu>
To: guile-user@gnu.org
Subject: Question about handling SIGINT properly in Guile
Date: Sat, 13 Apr 2024 10:46:16 -0400	[thread overview]
Message-ID: <87wmp1fhhj.fsf@vijaymarupudi.com> (raw)

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



             reply	other threads:[~2024-04-13 14:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-13 14:46 Vijay Marupudi [this message]
2024-04-13 16:46 ` Question about handling SIGINT properly in Guile 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wmp1fhhj.fsf@vijaymarupudi.com \
    --to=vijaymarupudi@gatech.edu \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).