How does one imitate SV_INTERRUPT?

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Mon Jun 17 07:03:37 AEST 1991


In article <13619 at mentor.cc.purdue.edu> woodcock at mentor.cc.purdue.edu (Bruce Sterling Woodcock) writes:
> The subject basically says it all.  I'm programming on a Sequent Symmetry
> using Dynix V3.0.12 which, unfortunately, doesn't support the SV_INTERRUPT
> flag.  Most systems after 4.2BSD have it.  To quote a 4.3BSD manual page:

One of BSD 4.2's biggest failures was forcing system calls to restart;
there are just too many applications where EINTR can't be ignored. Your
best bet is to use non-blocking I/O with select(). To force select() to
terminate, have it check readability on an empty pipe; inside the signal
handler, write a byte to the pipe, and read it back after the select().
(If you're worried about the possibility of receiving a few thousand
signals before the pipe is read, keep a global flag which says whether
the pipe is empty or not. Don't write unless the pipe is empty. Clear
the flag when you read the pipe. Make sure to set sv_mask so that you
don't have two signal handlers running at once.)

If all you want to do is wait for a signal to arrive: Create a pipe.
Set a flag to 0. Read one byte from the pipe; this will block. Inside
the signal handler, if the flag is 0, set it to 1 and write one byte to
the pipe. Once the byte has been read, close the pipe and continue.

---Dan



More information about the Comp.unix.questions mailing list