chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] reentrant signal handler?


From: Lui Fungsin
Subject: [Chicken-users] reentrant signal handler?
Date: Thu, 1 May 2008 16:47:08 -0700

Hi,

I know that the chicken core is not re entrant.
In that context, what's the usual practice for writing posix signal
handler in chicken?

See example program below.

If you type something, it will simply echo it.
You can type 'show' to print the a global flag.
Ctrl-C will set the flag to true.
If you hit ctrl-c rapidly, you'll send it into a loop consuming 100%
cpu. (ctrl-\ to quit it)

Am I correct that the signal handler written in scheme will be invoked
asynchronously?
How would one write this program in chicken correctly? Maybe there's a
way to do an atomic operation to set the flag?

Thanks,
fungsin.

(declare
 (uses extras regex posix utils srfi-13))
 (require 'regex)
 (require 'posix)
 (require 'utils)
(require-extension loop)

(define *user-interrupted?* #f)

(set-signal-handler!
 signal/int
 (lambda (signo)
   (set! *user-interrupted?* #t)))

(loop for l = (read-line)
      while (and l (not (eof-object? l)))
      if (string= l "show") do
      (print *user-interrupted?*)
      else if (string= l "exit") do
      (exit 0)
      else do
      (write-line l))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]