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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5400c39557b9f344 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-12-09 15:46:21 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!snoopy.risq.qc.ca!newsfeed.news2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!beastie.ix.netcom.com!nobody From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: Multitasking Date: Mon, 09 Dec 2002 12:48:57 -0800 Organization: >> Leaf-Eating Penguins? << Message-ID: References: <8bRwOT7FACB@lemmies.lb.bawue.de> <8bW1j8O+ACB@lemmies.lb.bawue.de> NNTP-Posting-Host: a5.f7.c8.7d Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit X-Server-Date: 9 Dec 2002 23:46:20 GMT User-Agent: KNode/0.6.1 X-noarchive: yes Xref: archiver1.google.com comp.lang.ada:31614 Date: 2002-12-09T23:46:20+00:00 List-Id: arvids lemchens fed this fish to the penguins on Monday 09 December 2002 01:54 am: > > Thought first i will receive seconds from somewhere of the 1970's and > was not sure if int or long would be enough, so i decided for > long_long. > From Ada.Calendar: subtype Day_Duration is Duration range 0.0 .. 86_400.0; function Clock return Time; function Year (Date : Time) return Year_Number; function Month (Date : Time) return Month_Number; function Day (Date : Time) return Day_Number; function Seconds (Date : Time) return Day_Duration; Seconds() returns seconds (floating point) since midnight (which also means your program could show odd results if run during a midnight cross-over. To avoid that (and apologies to those seeing the code yet again) try: with Ada.Text_IO; use Ada.Text_IO; with Ada.Calendar; use Ada.Calendar; with Ada.Float_Text_IO; use Ada.Float_Text_IO; Procedure tasktiming is runEpoch : Time := Clock; -- initialize program start time procedure myPutFloat(F :Float) is begin Put(F, Fore=>6, Aft=>5, Exp=>0); end; task type TC is entry S(D : Positive); end TC; task body TC is delayID : Positive; begin Put("A TC task has initiated at: "); myPutFloat(Float(Clock - runEpoch)); New_Line; loop select Accept S(D : In Positive) do Put("Task "); myPutFloat(Float(D)); Put(" Accepted at: "); myPutFloat(FLoat(Clock - runEpoch)); -- yes, ugly use of a global New_Line; delayID := D; end S; or terminate; end select; delay Standard.duration(delayID); Put("Task "); myPutFloat(Float(delayID)); Put(" finished at: "); myPutFloat(Float(Clock - runEpoch)); New_Line; end loop; end TC; TC_one, TC_two : TC; begin Put("Rendezvous Task TC_one at: "); myPutFloat(Float(Clock - runEpoch)); New_Line; TC_one.S(120); Put("Rendezvous Task TC_two at: "); myPutFloat(Float(Clock - runEpoch)); New_Line; TC_two.S(60); Put("Both tasks should be running "); New_Line; Put("Rendezvous Task TC_two at: "); myPutFloat(Float(Clock - runEpoch)); New_Line; TC_two.S(10); Put("Rendezvous Task TC_one at: "); myPutFloat(Float(Clock - runEpoch)); New_Line; TC_one.S(20); Put("Rendezvous Task TC_two at: "); myPutFloat(Float(Clock - runEpoch)); New_Line; TC_two.S(15); Put("Waiting for last task to finish"); New_Line; end TaskTiming; which gives the output relative to the start of the program itself. [wulfraed@beastie ada]$ ./tasktiming A TC task has initiated at: 0.00055 Rendezvous Task TC_one at: 0.00095 Task 120.00000 Accepted at: 0.00136 Rendezvous Task TC_two at: 0.00163 A TC task has initiated at: 0.00192 Task 60.00000 Accepted at: 0.00229 Both tasks should be running Rendezvous Task TC_two at: 0.00274 Task 60.00000 finished at: 60.00841 Task 10.00000 Accepted at: 60.00845 Rendezvous Task TC_one at: 60.00851 Task 10.00000 finished at: 70.01839 Task 120.00000 finished at: 120.00839 Task 20.00000 Accepted at: 120.00843 Rendezvous Task TC_two at: 120.00849 Task 15.00000 Accepted at: 120.00855 Waiting for last task to finish Task 15.00000 finished at: 135.01839 Task 20.00000 finished at: 140.01839 -- > ============================================================== < > wlfraed@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG < > wulfraed@dm.net | Bestiaria Support Staff < > ============================================================== < > Bestiaria Home Page: http://www.beastie.dm.net/ < > Home Page: http://www.dm.net/~wulfraed/ <