comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Semantics of statement reordering relevant to Ada.Real_Time
Date: Sun, 30 Mar 2008 17:28:19 -0400
Date: 2008-03-30T17:28:19-04:00	[thread overview]
Message-ID: <wccej9rucjw.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1e11c455-8cd3-4bb3-ab36-081455d2ae25@e23g2000prf.googlegroups.com

Eric Hughes <eric.eh9@gmail.com> writes:

> On Mar 30, 12:59 pm, Robert A Duff <bobd...@shell01.TheWorld.com>
> wrote:
>> The only thing that's guaranteed is I/O behavior, so you have to do some
>> I/O.
>
> Only?  You can also count on task termination, no?

Insofar as it affects I/O, yes.  And I suppose you can count on
termination of the program as a whole (that is, if all tasks
terminate, then so should the program).

>...Example code
> below.
>
> Eric
>
>
> with Ada.Real_Time ;
> with Ada.Text_IO ;
> procedure Foo
> is
>    Val : Natural := 0 ;

Better make that modular, or this conversion gets confused by the
overflow issue.  Oh, never mind, I see you reduced the counts,
and (if I can do that in my head correctly) it won't overflow. ;-)

>    Start_T, End_T : Ada.Real_Time.Time ;
>    use Ada.Real_Time ;
> begin
>    declare
>       task Start_Timer ;
>       task body Start_Timer is begin
>          Start_T := Ada.Real_Time.Clock ;
>       end ;
>    begin
>       null ;
>    end ;
>
>    declare
>       task Compute ;
>       task body Compute is begin
>          for K in 1 .. 10 loop
>             for I in 1 .. 10_000 loop
>                Val := Val + I * I ;
>             end loop;
>          end loop;
>       end ;
>    begin
>       null ;
>    end ;
>
>    declare
>       task End_Timer ;
>       task body End_Timer is begin
>          End_T := Ada.Real_Time.Clock ;
>       end ;
>    begin
>       null ;
>    end ;
>
>    Ada.Text_IO.Put_Line( Natural'Image( Val ) ) ;
>    Ada.Text_IO.Put_Line( Duration'Image( To_Duration( End_T -
> Start_T ) ) ) ;
>
> end Foo ;

I don't see any language rule that would prevent moving the calculation
of Val before or after the Start_Timer or End_Timer tasks, since they
don't use that value.  Or in parallel with them.  Or at compile time.

I'm not claiming that real compilers do these transformations
in practise, nor implying that they "should".

I suppose you could reasonably argue that the Clock in Start_Timer must
happen before the one in End_Timer (since a calculation based on those
values is printed out).  So I guess it would be wrong to print
a negative time span.

Meaningful benchmarking is hard!  ;-)

- Bob



      reply	other threads:[~2008-03-30 21:28 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-29 13:51 Ada.Real_Time behavior with GNAT kongra
2008-03-29 16:50 ` george.priv
2008-03-29 17:29   ` Georg Bauhaus
2008-03-29 19:06     ` george.priv
2008-03-29 19:15     ` Konrad Grzanek
2008-03-29 18:11 ` Simon Wright
2008-03-29 18:25 ` Dmitry A. Kazakov
2008-03-29 19:46   ` Konrad Grzanek
2008-03-29 21:21     ` george.priv
2008-03-29 21:49       ` Konrad Grzanek
2008-03-30  0:14     ` Georg Bauhaus
2008-03-30 17:12 ` Semantics of statement reordering relevant to Ada.Real_Time Eric Hughes
2008-03-30 18:59   ` Robert A Duff
2008-03-30 21:12     ` Eric Hughes
2008-03-30 21:28       ` Robert A Duff [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