[Python-Dev] Strategy for converting the decimal module to C

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Jul 26 09:39:40 CEST 2006


Nick Maclaren wrote:

> The compiled code has made a data structure temporarily inconsistent
> because the operation is safe (say, list insertion), and then gets an
> asynchronous interrupt (e.g. SIGINT).  The SIGINT handler does some
> operation (e.g. I/O) that implicitly uses floating-point, which then
> interrupts.

Well, of course anything can be made to happen asynchronously
by calling it from something asynchronous, such as a SIGINT
handler. That doesn't change the fact that the floating
point operation itself is deterministic, including whether
it causes an exception.

Well-written programs don't do any more in a signal handler
than is absolutely necessary, for reasons which apply equally
well whether floating point is involved or not. I'd say
the mistake was made right at the beginning by assuming
that the data structure in question was safe while allowing
a SIGINT to occur to a handler that's not careful enough
about what it does.

BTW, it seems to me you could get exactly the same problem
if FP exceptions were handled entirely in user mode, as
you suggest. Not that I don't agree that would be a good
idea -- I do -- but it wouldn't prevent this particular
kind of mistake.

And all of this is getting rather far away from where we
started, which was simply instrumenting a piece of code
to count floating point exceptions. Such a program isn't
going to be doing I/O in SIGINT handlers or installing
FP exception handlers that mess with unrelated critical
data structures.

--
Greg


More information about the Python-Dev mailing list