www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/18/15:10:56

Date: Fri, 18 Dec 1998 15:10:31 -0500 (EST)
From: Daniel Reed <djr AT narnia DOT n DOT ml DOT org>
To: djgpp AT delorie DOT com
Subject: Re: [Re: cpu eater]
In-Reply-To: <19981218134712.25514.qmail@www0s.netaddress.usa.net>
Message-ID: <Pine.LNX.4.05.9812181505580.22758-100000@narnia.n.ml.org>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com

On 18 Dec 1998, ADAM SCHROTENBOER wrote:
) If you want to release the time slice, write your own sleep function.
Okay...

) >I was expecting the program to sleep quietly for 5 secs and then
) >continue
) >the while();
#include <time.h>

int	mysleep(int seconds) {
	struct timeval	tv;

	tv.tv_sec = seconds;
	tv.tv_usec = 0;
	select(0, NULL, NULL, NULL, &tv);
	return(tv.tv_sec);
}

That should emulate sleep() pretty well. If the mysleep() call is
interrupted during the select(), it'll return the number of seconds
remaining in the sleep timeout, just like the standard sleep() does.

-- 
Daniel Reed <n AT ml DOT org>
I'll never forget the first time I ran Windows, but I'm trying...

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019