Question: signal and program termination

Guido van Rossum guido at cwi.nl
Fri Feb 1 01:49:06 AEST 1991


scjones at thor.UUCP (Larry Jones) writes:

>The difference is that exit() exits from the program without the
>interrupted operation ever being resumed.  Although it is possible
>that the exit handlers could fail because an interrupted operation
>left some global data in a fatally inconsistent state, careful
>coding should be able to prevent fatally inconsistent states.  A
>quality implementation should code all the library routines this
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>way.
 ^^^^

I doubt it.  Both the C standard and POSIX explicitly forbid the use in
signal handlers of printf(), malloc() and related things for exactly
this reason: if you get an asynchronous signal while one of these is
manipulating its global state, you may be in trouble if you try to use
that global state from the handler.  Relying on "quality
implementations" only passes the problem on to the poor guy who has to
port your code to a platform with only a lesser-quality implementation
available.  BTW, most of today's stdio and malloc implementations are
lesser-quality, according tou your standards...

--
Guido van Rossum, CWI, Amsterdam <guido at cwi.nl>
"It's a bit runny, sir"



More information about the Comp.std.c mailing list