comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitriy Anisimkov <anisimkov@yahoo.com>
To: Jano <nono@celes.unizar.es>
Subject: Re: Help with anormal pausing of program
Date: Wed, 11 Jun 2003 21:31:07 +0700
Date: 2003-06-11T21:31:07+07:00	[thread overview]
Message-ID: <3EE73D2B.4010502@yahoo.com> (raw)
In-Reply-To: <MPG.19508a2de77d0e4c989718@News.CIS.DFN.DE>

Jano wrote:
> The problem is that I've detected that some (many) of these tasks are 
> being stopped for unusual long times, after some running time. It seems 
> like I issue a delay 1.0 but they sleep for much more. I haven't find 
> any deadlock or critical race condition anywhere, CPU usage is idle.

I had the same problem. It was becouse of wrong result from QueryPerformcnceCounter Win32 API call on some hardware configurations. GNAT for Win32 is counting time by using QueryPerformcnceCounter call. Some hardware configurations could make this counter to be wrong sometimes. See article in the MSDN

http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B274323

it is talking about leap counter forward, and contain program in C to detect it.

I was encounter the leap counter backward, and wrote program in Ada to detect it.

See the sources to understand how to use it.

Very short description is:
Press a key '1' then counter would checked 10000 times for the next counter is bigger than previous,
if it is not so the message
[prev_counter] > [next_counter] would appear.

Press '2' the same checking would be 20000, etcetera till '9'

------------------------------------
with System.OS_Interface;
with Ada.Text_IO;

procedure Time is
   use Ada.Text_IO;
   use System.OS_Interface;

   Perf_Freq : aliased LARGE_INTEGER;
   Curr_Counter, Prev_Counter : aliased LARGE_INTEGER;
   Char : Character;
   Pass : Natural := 0;
   Max_Diff : LARGE_INTEGER := 0.0;
   Diff : LARGE_INTEGER;

   procedure Check (Item : BOOL);
   pragma Inline (Check);

   procedure Check (Item : BOOL) is
   begin
      if not Item then
         raise Program_Error;
      end if;
   end Check;

begin
   Check (QueryPerformanceFrequency (Perf_Freq'Access));
   Put_Line (LARGE_INTEGER'Image (Perf_Freq));

   Check (QueryPerformanceCounter (Prev_Counter'Access));

   loop
      Check (QueryPerformanceCounter (Curr_Counter'Access));

      Diff := Curr_Counter - Prev_Counter;

      if Diff < 0.0 then
         Put_Line (LARGE_INTEGER'Image (Prev_Counter)
                   & " >" & LARGE_INTEGER'Image (Curr_Counter));
      elsif Diff > Max_Diff then
         Max_Diff := Diff;
      end if;

      Prev_Counter := Curr_Counter;

      if Pass = 0 then
         Get_Immediate (Char);

         case Char is
         when '0' =>
            Put_Line (LARGE_INTEGER'Image (Curr_Counter));
         when 'f' | 'F' =>
            Check (QueryPerformanceFrequency (Perf_Freq'Access));
            Put_Line (LARGE_INTEGER'Image (Perf_Freq));
         when '1' .. '9' =>
            Pass := Integer'Value ("" & Char) * 10000;
            Max_Diff := 0.0;
            Check (QueryPerformanceCounter (Prev_Counter'Access));
         when 'q' | 'Q' => exit;
         when others => Put (Char);
         end case;
      else
         Pass := Pass - 1;

         if Pass = 0 then
            Put_Line (LARGE_INTEGER'Image (Curr_Counter)
                      & LARGE_INTEGER'Image (Max_Diff));
         end if;
      end if;
   end loop;
end Time;
-----------------------------------




  reply	other threads:[~2003-06-11 14:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-10 23:37 Help with anormal pausing of program Jano
2003-06-11 14:31 ` Dmitriy Anisimkov [this message]
2003-06-11 18:42   ` Jano
2003-06-11 19:54     ` Pascal Obry
2003-06-12  2:21     ` Anisimkov
2003-06-12  6:31       ` Jano
2003-06-12  7:26         ` tmoran
2003-06-12  7:47           ` Jano
2003-06-12  9:43           ` Georg Bauhaus
2003-06-12 17:09             ` tmoran
2003-06-12 22:19               ` Georg Bauhaus
2003-06-13 18:13               ` Jano
2003-06-14  4:59                 ` tmoran
2003-06-12  7:47         ` Jano
2003-06-12 12:59           ` Dmitriy Anisimkov
2003-06-12  8:32         ` Preben Randhol
2003-06-12  7:06       ` Vinzent Hoefler
2003-06-13 13:35         ` Dmitriy Anisimkov
2003-06-11 20:16   ` tmoran
2003-06-11 21:11     ` Jano
2003-06-11 22:36       ` tmoran
2003-06-12  6:38         ` Jano
2003-06-12 18:08   ` Wiljan Derks
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox