Bug in Delay
frank at g-n-u.de
Tue Mar 27 04:29:49 CEST 2001
Maurice Lombardi wrote:
> Olivier Pécheux wrote:
> > Hi,
> > Some of my beginners found that Delay work proprely for timing more than
> > 12 ms. Under 11 are no delay but the C'delay do.
> > I don't find it in the Bug list.
> in PC's time is usually increased by a hardware timer with ticks
> every 1/60th second.
Almost. It's ~ 1/18.2 seconds, and it's only under Dos. Linux, e.g.,
uses 1/100 s on PCs.
To get an integer number of CLOCKS_PER_SEC, DJGPP multiplies the
ticks by 5 internally, so we have 1/91 s. Therefore, every delay
shorter than that is considered equal to 0 by usleep() (which is
used internally by Delay).
> So this does not seem unreasonable. Are you
> sure that the C routine you speak about measure really
> microseconds, or just put out a number in microseconds which is in
> fact the one given by ticks of the timer ? What is actually the C
> function you use to measure the delay ?
I don't know how Olivier measured it, but if I call Delay(11)
several times in a loop, I can immediately see that it doesn't wait.
Well, on Dos with such a poor time resolution it's difficult to get
satisfactory short delays. Maybe the only way to do it (besides
messing with the hardware which will surely conflict with a lot of
other programs etc.) is busy waiting like Borland did in BP which
has some serious problems, like eating up CPU time unnecessarily and
getting the delay wrong during the whole program if the system is
busy during calibration (and I'm not even talking about the famous
bugs). The first problem could be alleviated by doing busy waiting
only for short delays where the waste doesn't matter so much, and
use usleep() (which yields the processor while waiting) for longer
I'm not sure if it's worth the extra effort -- otherwise it might
just boil down to: If you want a good delay, use an OS that supports
it without any tricks...
In any way, I can't write such code because I have studied Borland's
Delay code far too well in the past so it might be a little
copyright problem if I'd write something similar for GPC. Maybe
someone else likes to write the code -- not based on Borland's code,
though the idea may be the same; if you want, I can tell you the
idea in words, and you can translate it in code (clean
Frank Heckenbach, frank at g-n-u.de, http://fjf.gnu.de/
GPC To-Do list, latest features, fixed bugs:
More information about the Gpc