Date: Sun, 15 Aug 1999 14:09:13 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Simon Redwood 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: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.