In article <11*********************@u72g2000cwu.googlegroups. com>,
ma***********@gmail.com <ma***********@gmail.com> wrote:
Why would a signal handler cannot in general call standard library
functions.
I have read whats is said in Standard but needs an explaination on that
as i couldn't uunderstand it.
A signal handler can interrupt existing operations (including
library calls) between sequence points, possibly even
terminating an time-consuming instruction (such as division)
{requiring that the instruction be restarted when the handler
completes.}
Library calls are allowed to have internal persistant state
that might get overwritten if the same library call were invoked
in the signal handler. Or possibly even a different library call,
as there are tight ties between some of them.
I/O is the obvious example: if a library routine is just about
to update the buffer pointer when an I/O routine gets invoked
in the signal handler, then the result could be program crashes
that were quite difficult to track down.
Rather than put restrictions on the ways that each library function
may use persistant state, the C standard says "Only these very few
things are certain to be safe."
There are other standards, such as POSIX.1, that go into much more
detail about exactly which routines are safe in signal handlers
and which ones are not. POSIX.1 does not invalidate this section
of the C standard, as C allows implementations to offer additional
functionality... but if you used a POSIX.1 guarantee of safety then
as soon as you took your C program to a non-POSIX.1 system, all
bets would be off again.
--
Okay, buzzwords only. Two syllables, tops. -- Laurie Anderson