Mail Archives: djgpp/1997/07/26/11:33:01
On 24 Jul 1997 07:07:03 GMT, jmarin AT pyy DOT jmp DOT fi (Jukka Marin) wrote:
> I'm new to djgpp (and dos programming in general :-) I'm trying to write
> a packet protocol which requires small, but accurate time delays. I was
> happy to find the usleep() call - and unhappy to find out it doesn't
> work properly. Not on my hardware, at least.
>
> If I have a loop like this:
>
> while(1) {
> printf("huu\n");
> for (i = 0; i < 1000; i++) usleep(1000);
> }
>
> The printf() is being run as fast as it can, it seems - ie. the usleep()
> call doesn't delay the execution at all. If I change the usleep argument
> to 100000, I get a delay - but I need 1 ms delays, not 100 ms ones.
usleep() does not provide 1 ms delay, because it is based on clock()
which in turn has a resolution of 55 ms. You can use a homebrew version
of usleep(), e.g.:
#include <dpmi.h>
#include "puclock.h"
unsigned int
pusleep(unsigned int _useconds)
{
uclock_t stop_time = puclock() + _useconds * (uclock_t)UCLOCKS_PER_SEC
/ 1e6;
while (puclock() < stop_time)
{
__dpmi_yield();
}
return 0;
}
This code uses the puclock() function posted here a few weeks ago. See
this list's archive at www.delorie.com or drop me a line and I'll send
it to you (ca. 3KB).
uclock() uses the timer chip and does not work inside a Windows/Win95
DOS box, because Windows fiddles with the timer chip. puclock()
overcomes this problem because it uses Virtual Timer Device if it runs
inside a Windows DOS box.
Regards...
Michael
--
Spammers: ask secretreports AT answerme DOT com for free info
about how to explode your business.
hoefner AT ddv DOT de wants to learn more about spam and UCE. Please help him.
- Raw text -