Re: Moving main loop to GLib.



Jeff Garzik <jgarzik@pobox.com> writes:

> I seem to remember that calling system calls from a signal handler might
> not be a good idea.

I have nothing authoritative to say about this, but I think ANSI
allows almost nothing in signal handlers, while POSIX has more
head-room.  Anyway, here is the self-pipe trick, by D. J. Bernstein.
I trust him very much about `getting it right'.

    The self-pipe trick

    Conventional wisdom says that you can't safely mix select() with
    SIGCHLD (or other signals): the SIGCHLD might go off while
    select() is starting, too early to interrupt it, too late to
    change its timeout.

    Solution: the self-pipe trick. Maintain a pipe and select for
    readability on the pipe input. Inside the SIGCHLD handler, write a
    byte (non-blocking, just in case) to the pipe output. Done.

    Of course, the Right Thing would be to have fork() return a file
    descriptor, not a process ID.



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