Behaviour of setjmp/longjmp and registers

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jan 28 16:57:40 AEST 1989


In article <470 at maxim.ERBE.SE> prc at maxim.ERBE.SE (Robert Claeson) writes:
>Now, make this portable and non  CPU-intensive. If you think the
>algorithm needs to be changed, just tell me.

I assume you're not using stdio to do this, since longjmping from
a signal handler is unsafe if a stdio routine was active at the
time of the alarm.  A SVID-conforming UNIX provides several ways
to do the sort of thing you're attempting, for example using VMIN
and VTIME which obviate the need for SIGALRM.  Or, you could just
set a global flag in your alarm handler and return, since a SVID-
conforming UNIX will abort a read() from a terminal when the alarm
occurs.  By testing for EINTR after the read() returns, and using
the global flag as additional verification, you can make the main
control logic do the right thing.

There is no fully portable way to do what you're attempting, and
using longjmp is not a solution because it is unreliable in this
context.



More information about the Comp.lang.c mailing list