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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,101c38a932801b81 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!198.186.194.247.MISMATCH!news-out.readnews.com!transit3.readnews.com!panix!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Semantics of statement reordering relevant to Ada.Real_Time Date: Sun, 30 Mar 2008 17:28:19 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1e11c455-8cd3-4bb3-ab36-081455d2ae25@e23g2000prf.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1206912499 4600 192.74.137.71 (30 Mar 2008 21:28:19 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Sun, 30 Mar 2008 21:28:19 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:QYw51g2XNcZPbGKziovEreZQKFY= Xref: g2news1.google.com comp.lang.ada:20652 Date: 2008-03-30T17:28:19-04:00 List-Id: Eric Hughes writes: > On Mar 30, 12:59 pm, Robert A Duff > 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