Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix-wizards Subject: Re: sub-second sleeps on BSD 4.2 Message-ID: <5173@umcp-cs.UUCP> Date: Wed, 24-Apr-85 23:36:37 EST Article-I.D.: umcp-cs.5173 Posted: Wed Apr 24 23:36:37 1985 Date-Received: Sat, 27-Apr-85 00:08:55 EST References: <408@psivax.UUCP> Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 28 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@umcp-cs ARPA: chris@maryland