sub-second sleeps on BSD 4.2
Chris Torek
chris at umcp-cs.UUCP
Thu Apr 25 14:36:37 AEST 1985
Your code is one big race condition. If you aren't interested in
preserving the old interval timer, then use this (I've deleted the
unchanged code):
delay()
{
int omask, nmask;
#define mask(x) (1 << ((x) - 1))
signal(SIGALRM, nullfunc);
wakeup = 0;
omask = sigblock(mask(SIGALRM));
nmask = omask & ~mask(SIGALRM);
if (setitimer(ITIMER_REAL, &tm, (struct timeval *)NULL))
exit(1);
while (wakeup == 0)
sigpause(nmask);
sigsetmask(omask);
}
I'm assuming that sigpause() restores the signal mask that was in
effect before it's call; there is some very bogus-looking code in
the 4.2BSD kernel that is intended to do that, but I've never tested
it....
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251)
UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at maryland
More information about the Comp.unix.wizards
mailing list