comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: Multitasking
Date: Mon, 09 Dec 2002 12:48:57 -0800
Date: 2002-12-09T23:46:20+00:00	[thread overview]
Message-ID: <qjv2ta.lc4.ln@beastie.ix.netcom.com> (raw)
In-Reply-To: 8bW1j8O+ACB@lemmies.lb.bawue.de

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/             <




  reply	other threads:[~2002-12-09 20:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-07 12:16 Multitasking arvids lemchens
2002-12-07 14:09 ` Multitasking SteveD
2002-12-09  7:43   ` Multitasking arvids lemchens
2002-12-07 14:10 ` Multitasking Michal Nowak
2002-12-09  9:57   ` Multitasking arvids lemchens
2002-12-09 22:27     ` Multitasking Michal Nowak
2002-12-07 21:33 ` Multitasking Dennis Lee Bieber
2002-12-08  0:17   ` Multitasking Dennis Lee Bieber
2002-12-09  9:54     ` Multitasking arvids lemchens
2002-12-09 20:48       ` Dennis Lee Bieber [this message]
2002-12-11 12:45         ` Multitasking John English
2002-12-11 19:34           ` Multitasking Dennis Lee Bieber
replies disabled

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