comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: ATC, an  example please.
Date: Thu, 30 Jun 2005 11:32:38 +0200
Date: 2005-06-30T11:32:38+02:00	[thread overview]
Message-ID: <efd7io46aiw$.1a88j118jl2sf$.dlg@40tude.net> (raw)
In-Reply-To: 1120121092.240284.285260@g14g2000cwa.googlegroups.com

On 30 Jun 2005 01:44:52 -0700, e.coli wrote:

> how ATC work?

ATC transfers control, it does not abort any other task. This is why you
have to explicitly kill the task. Another error in your code is that you
wait not for the calculation completion, but for its initiation.

> can you fix this example,please?

Try this:

with Ada.Text_Io;

procedure Atc_Test is
   task A_Task is
      entry Start;
      entry Ready;
   end A_Task;

   task body A_Task is
   begin
      loop
         accept Start;
         Ada.Text_Io.Put_Line("one.start");
         for Iteration in 1..100_0000 loop
            Ada.Text_Io.Put (".");
         end loop;
         accept Ready;
         Ada.Text_Io.Put_Line("one.end");
      end loop;
   end A_Task;

begin
   A_Task.Start;      -- Initiate calculation
   select
      delay 2.0;      -- After time-out expiration,
      abort A_Task;   -- kill the task!
      Ada.Text_Io.Put_Line ("Long calculation abandoned");
   then
      abort A_Task.Ready;   -- Wait for completion
   end select;
   Ada.Text_Io.Put_Line ("end main");

end Atc_Test;

----------------------
N.B. This is a wrong way to do things. Don't use ATC if you cannot prove
that there is no other way. Don't abort task, which is even more brutal
than ATC.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2005-06-30  9:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-30  8:44 ATC, an example please e.coli
2005-06-30  9:32 ` Dmitry A. Kazakov [this message]
2005-06-30  9:59   ` e.coli
2005-06-30 11:06   ` Christoph Grein
2005-06-30 12:55   ` Robert A Duff
2005-06-30 15:29     ` Dmitry A. Kazakov
2005-06-30 20:31       ` Robert A Duff
2005-06-30  9:32 ` e.coli
2005-07-02  8:18 ` Craig Carey
replies disabled

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