sleep(3) uses longjmp and SIGALRM

Peter Jeremy peter at stca77.stc.oz
Mon Oct 10 17:33:10 AEST 1988


In article <823 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>In article <1988Sep28.135914.25444 at lsuc.uucp> dave at lsuc.uucp (David Sherman) writes:
>> [ Interactions between sleep(), SIGUSER, longjmp(), pause() ]
> [ isn't longjmp() ]
>What may certainly cause you trouble is the setting of the alarm clock
>in sleep(); this will conflict with your setting of it, unless it is
>implemented clean enough to restore the original alarm time and setting
>of the interrupt handler. If it isn't, why not write your own?

Looking at my XENIX system, sleep() will save and restore your alarm()
setting.  I did discover a bug with some of my code that used sleep(1)
for short timeouts - occasionally it would stop.  When I looked at sleep()
closely, I found that there is a hole between the alarm() and pause() calls
(about 20 usec on a 8MHz 80286 from memory) that would occasionally let the
alarm() timeout before it paused - hence the pause() waited until the next
signal.  A bit embarrasing...  I got around it by using nap() or longer
sleeps.  I suspect the bug exists in all library versions of sleep(), so
it may be worth checking if you use 'sleep(1);' at all.
-- 
Peter Jeremy (VK2PJ)         peter at stca77.stc.oz
Alcatel-STC Australia        ...!munnari!stca77.stc.oz!peter
41 Mandible St               peter%stca77.stc.oz at uunet.UU.NET
ALEXANDRIA  NSW  2015



More information about the Comp.unix.wizards mailing list