From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,349427c451f66022 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder.news-service.com!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Strange behaviour of delay in Windows XP Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: Date: Fri, 8 Oct 2010 09:54:37 +0200 Message-ID: <16p5l53nudhpa.cxcrndddsok0.dlg@40tude.net> NNTP-Posting-Date: 08 Oct 2010 09:54:38 CEST NNTP-Posting-Host: 051afd2e.newsspool3.arcor-online.net X-Trace: DXC=J=ec3kle`UTaoembcbF;DQMcF=Q^Z^V3X4Fo<]lROoRQ8kF 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