sleep()

chris at umcp-cs.UUCP chris at umcp-cs.UUCP
Tue Jul 5 20:48:47 AEST 1983


I  have a bone to pick with the C library "sleep" routine.  First, some
background:

The  way  sleep  works  is  something like this:  set a signal trap for
SIGALRM, set the alarm, and pause forever.  When the SIGALRM  hits  the
trap function uses longjmp to break out of the for(;;).

Now here's what can go wrong:

While  pause()d, suppose a SIGHUP arrives.  The SIGHUP handler wants to
write something to a file, then clean  up  and  exit.    So  it  begins
processing  (with  SIGHUP  carefully  turned off).  Meanwhile the alarm
clock is still ticking away.  Suddenly the alarm goes  off,  and  (here
comes  the  bug)  the  longjmp() RETURNS FROM THE sleep() CALL.  No one
even notices that a hangup was being processed!

Seems  to  me  the way sleep() ought to work is:  set a signal trap for
SIGALRM, clear an alarmed flag, set the alarm, and  while  the  alarmed
flag is clear, pause.  Using longjmp() was an outright mistake.

Anyone  see  any  problem  with  this?  I've been using it in Emacs for
quite a while now with no trouble.  (I needed to  prevent  the  longjmp
for the echo-keystrokes mod.)

					- Chris
-- 
UUCP:	{seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet:	chris at umcp-cs
ARPA:	chris.umcp-cs at UDel-Relay



More information about the Comp.unix.wizards mailing list