Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site artecon.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!ittatc!dcdwest!sdcsvax!celerity!telesoft!artecon!jim From: jim@artecon.UUCP (Jim Wang) Newsgroups: net.unix-wizards Subject: Use of 4.2 select(2) call for sub-second sleeps Message-ID: <109@artecon.UUCP> Date: Thu, 16-Jan-86 17:44:07 EST Article-I.D.: artecon.109 Posted: Thu Jan 16 17:44:07 1986 Date-Received: Mon, 20-Jan-86 06:00:48 EST Organization: Artecon Inc., Carlsbad, Ca. Lines: 47 Is there any reason why the select(2) system call on 4.2bsd systems can't be used for a quick and dirty (QND) sub-second sleep? Granted that it is not portable to non-Berkeley, but in cases where that is not a consideration, it has a few advantages: 1) Does not require setting up a timer (You don't have to remember all those nested structures). 2) You don't have to worry about taking over the SIGALRM signal. You also needn't set up a dummy routine that does nothing except provide a place to point to. 3) Most importantly, you don't have to worry about critical races where the timer expires before the signal catcher is set up. These are a distinct possibility for sub-second intervals. Not knowing how select() works internally, I can't determine if a tremendous amount of overhead is required. I have used it in a number of applications (see below for example) without apparent detrimental effects, but I've wondered if perhaps I'm missing something. Jim Wang Artecon, Inc. (jim@seismo, seismo!kobold!artecon!jim) ----------------------------------------------------- #include #include static void nap(seconds, microseconds) int seconds, microseconds; { struct timeval timeout; timeout.tv_sec = seconds; timeout.tv_usec = microseconds; (void) select(1, 0, 0, 0, &timeout); } /* That's all there is to it. */