delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/07/26/11:33:01

From: mauch AT uni-duisburg DOT de (Michael Mauch)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: usleep() and 95dos problems
Date: Fri, 25 Jul 1997 10:34:37 +0200
Organization: Home, sweet home (via Gesamthochschule Duisburg)
Lines: 56
Message-ID: <5r9oet$q1d$1@news-hrz.uni-duisburg.de>
References: <slrn5tdvon DOT 1hb DOT jmarin AT pyy DOT jmp DOT fi>
NNTP-Posting-Host: ppp66.uni-duisburg.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


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