From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Strange behaviour of delay in Windows XP
Date: Fri, 8 Oct 2010 09:54:37 +0200
Date: 2010-10-08T09:54:38+02:00 [thread overview]
Message-ID: <16p5l53nudhpa.cxcrndddsok0.dlg@40tude.net> (raw)
In-Reply-To: i8lcl2$f0i$1@news.eternal-september.org
On Thu, 07 Oct 2010 23:04:33 +0200, michael bode wrote:
> I've seen a very strange behaviour of the delay statement with GNAT on a
> Windows XP machine. This is the code:
>
> with Ada.Text_Io; use Ada.Text_Io;
> with Ada.Calendar; use Ada.Calendar;
>
> procedure Testprog is
> T1, T2 : Time;
> D : Duration;
> begin
> D := 1.0;
> T1 := Clock;
> delay D;
> T2 := Clock;
> Put_Line ("Expected delay:" & Duration'Image(D));
> Put_Line ("Actual delay:" & Duration'Image(T2-T1));
> end Testprog;
>
> And this is what it prints when run on Linux:
>
> Expected delay: 1.000000000
> Actual delay: 1.000321000
>
> But I have a (or rather 2) Dell Vostro MT 220 PC where the actual delay
> is about 2.7s instead.
What happens with this:
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Calendar; use Ada.Calendar;
with Win32.Mmsystem; use Win32.Mmsystem;
with Win32.WinBase; use Win32.WinBase;
procedure Testprog is
T1, T2 : Time;
D : Duration;
use type Win32.BOOL;
begin
if TIMERR_NOERROR /= timeBeginPeriod (1) then
raise Program_Error;
end if;
if 0 = SetThreadPriority (GetCurrentThread,
THREAD_PRIORITY_TIME_CRITICAL) then
raise Program_Error;
end if;
delay 1.0; -- Let the dust settle down
D := 1.0;
T1 := Clock;
delay D;
T2 := Clock;
Put_Line ("Expected delay:" & Duration'Image(D));
Put_Line ("Actual delay:" & Duration'Image(T2-T1));
end Testprog;
timeBeginPeriod (1) changes the resolution of timer to 1ms. Some older
systems had 10ms by default.
SetThreadPriority changes the priority to R-T.
> Any ideas or should I call a feng shui master?
Turn down indexing service, anti-virus software and whatever mess is
running on the computer in background.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
prev parent reply other threads:[~2010-10-08 7:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-07 21:04 Strange behaviour of delay in Windows XP michael bode
2010-10-07 21:35 ` Vinzent Hoefler
2010-10-07 22:10 ` michael bode
2010-10-07 22:37 ` Jeffrey Carter
2010-10-08 5:18 ` michael bode
2010-10-08 10:13 ` michael bode
2010-10-08 0:15 ` Randy Brukardt
2010-10-08 5:33 ` michael bode
2010-10-09 6:42 ` Randy Brukardt
2010-10-09 8:18 ` Dmitry A. Kazakov
2010-10-26 1:50 ` Yannick Duchêne (Hibou57)
2010-10-08 7:54 ` Dmitry A. Kazakov [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox