pspp-dev
[Top][All Lists]
Advanced

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

Re: netbsd build update


From: Ben Pfaff
Subject: Re: netbsd build update
Date: Fri, 19 May 2006 17:55:33 -0700
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

John Darrington <address@hidden> writes:

> On Fri, May 19, 2006 at 07:17:48AM -0700, Ben Pfaff wrote:
>      > Provided that sigaction (part of the POSIX standard) is supported we
>      > can reliably overcome this problem thus:
>      >
>      > We have two signal handlers:  fpe_handler_ignore, which does nothing,
>      > and fpe_handler_warn which a) logs a warning message, b) resets the
>      > handler to fpe_handler_ignore, and c) returns.
>      >
>      > At the start of every procedure, the active handler is reset to 
>      > fpe_handler_warn.   Thus, when a FPE occurs, the user gets a warning,
>      > the handler is set to ignore further FPEs and the procedure completes
>      > normally.  The user gets his results, but has been warned that they
>      > might not be correct.
>
>      (Doing I/O in a signal handler is really a bad idea.)
>
> True.  Signal handlers need to be fast.

Well, mostly it's because the functions for doing I/O are not
reentrant, but it's certainly true that signal handlers should be
fast too.

>      We still need to be able to mask exceptions, though.  Otherwise,
>      fpe_handler_ignore will just get called in an infinite loop,
>      which is not an improvement.  Thus, I believe that we really want
>      "fpe_handler_record".
>
> Yes.  Posix provides sigprocmask to do this.

That's the wrong approach.  Masking that kind of signal is likely
to cause just the same kind of infinite loop, except that in this
case the loop will be between the kernel and the faulting
instruction instead of involving a signal handler, too.  You want
to mask the exception's generation, not its handling.

In fact SUSv3 says that blocking SIGFPE causes undefined
behavior.  See the SUSv3 entry for sigprocmask():

    If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are
    generated while they are blocked, the result is undefined, unless
    the signal was generated by the kill() function, the sigqueue()
    function, or the raise() function.

We can use SUSv3 (and C99's) feholdexcept() to mask exception
generation.  (Where available, we already do.)
-- 
Ben Pfaff 
email: address@hidden
web: http://benpfaff.org




reply via email to

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