Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!seismo!rlgvax!cvl!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.unix-wizards Subject: sleep() Message-ID: <460@umcp-cs.UUCP> Date: Tue, 5-Jul-83 06:48:47 EDT Article-I.D.: umcp-cs.460 Posted: Tue Jul 5 06:48:47 1983 Date-Received: Thu, 7-Jul-83 03:36:56 EDT Organization: Univ. of Maryland, Computer Science Dept. Lines: 29 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@umcp-cs ARPA: chris.umcp-cs@UDel-Relay