[racket] SIgnal-catching in Racket
You're right that can't post to a Racket semaphore in a signal handler.
The way to allocate a global and make it available to Racket code is to
create a new kind of event; the 2006 post is still accurate. In
particular, the new event's polling function (which is called by the
scheduler) can check the global. Calling scheme_signal_received() from
a signal handler ensures that the event's polling function is called
after the global is changed.
A self-pipe is also a fine approach, since the event wrapper for a pipe
is already available via scheme_make_fd_input_port().
At Sat, 20 Dec 2014 14:05:32 -0500, Tony Garnock-Jones wrote:
> Hi all,
>
> If I wanted to catch a Unix signal (say, SIGUSR1) within my Racket
> program, how should I go about it?
>
> My current best guess is:
> - load a C extension, which
> - creates a semaphore and
> - hooks the signal with a handler (MZ_SIGSET looks relevant), which
> - posts to the semaphore when the signal arrives.
>
> However this seems like a recipe for problems. Is it even permitted to
> post to a semaphore from a signal handler? Will the runtime be upset
> about unscheduled intrusions into its demesne? Is it possible for a C
> extension to allocate a global value like a semaphore and make it
> available to Racket code?
>
> Is there a better way?
>
> - Perhaps a self-pipe would be better than a semaphore?
> - A thread from 2006 [1] points at scheme_signal_received() but
> I don't understand why creating an event type is the right thing
> to do.
>
> Tony
>
> [1] http://lists.racket-lang.org/users/archive/2006-July/013999.html
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users