cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/08/15/11:42:13

Date: Sun, 15 Aug 1999 14:09:13 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Simon Redwood <spredwood AT sri-net DOT demon DOT co DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: usleep/delay/sleep ?
In-Reply-To: <934647567.25013.0.nnrp-11.c2de6b60@news.demon.co.uk>
Message-ID: <Pine.SUN.3.91.990815140434.1935i-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

On Sat, 14 Aug 1999, Simon Redwood wrote:

> I am new to using djgpp under dos, being a unix programmer.  I am having
> trouble with delays.
> 
> Can I rely on usleep to give me accurate timings.
> 
> Giving usleep a value of 10000-12500 produces the same delay, whereas 13000
> gives the same as 20000, where I am going wrong.

This is all expected behavior: usleep has a 55-msec granularity.  (This 
is unfortunately not stressed in the docs; v2.03 fixes that.)  The system 
clock on the PC ticks 18.2 times a second, so this is what you get.

> I would like to put a delay into a loop of about 1/100 sec. how is the best
> way to acheive this

Write your own wait loop that calls uclock.  This function has 
840-nanosecond resolution.

> I am also looking to work with microprocessors where I will need accurate
> timings of nanoseconds, how can this be best acheived.

One way is to use the machine instruction that reads the counter register 
of the Pentium and later CPUs.

- Raw text -


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