comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: task time-out&abort
Date: 29 Jun 2005 16:52:21 -0400
Date: 2005-06-29T16:52:21-04:00	[thread overview]
Message-ID: <wccwtocsx6i.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1119540379.606416.227950@z14g2000cwz.googlegroups.com

"e.coli" <maurizio.ferracini@gmail.com> writes:

> e.coli ha scritto:
> > here the code...
> 
> 
> i have this simple code...
> ------------------------------------
>   with Ada.Text_Io;
> 
> procedure Sempliced2 is
> 
>    task A_Task is
>       entry Uno;
>    end A_Task;
> 
>    task body A_Task is
>    begin
>       loop
>          select
>          accept Uno do
>             Ada.Text_Io.Put_Line("i do something");
>             --here code like
>             --Horribly_Complicated_Recursive_Function(x,y);
>          end Uno;
>       or
>          terminate;
>       end select;
>    end loop;
> end A_Task;
> 
> begin --corpo genitore
>    A_Task.Uno;
> end Sempliced2;
> ------------------------------------------------
> 
> Speliced2 call the task entry uno.
> now how Speliced2 can terminate the execution of the entry "uno" before
> the
> end of the call (es. time-out)?

You can put the Horribly_Complicated_Recursive_Function inside an ATC:

    select
        delay 5.0;
    then abort
        Horribly_Complicated_Recursive_Function...
    end select;

And you can pass the time-out as a parameter to the entry call,
if you like.

But be careful!  ATC is a very dangerous feature, which is difficult to
get right.  And if you get it wrong, you will have nasty
timing-dependent bugs.

The problem is that any variables modified by
Horribly_Complicated_Recursive_Function can be destroyed
when it gets aborted by the timeout.  The usual way to deal with it
is to do most of the work in local data that nobody else looks at.
And it can update some more-global thing (like an 'out' parameter of the
entry) in an abort-deferred way -- using a protected object, or a pragma
Atomic.

I think there are some examples in the Ada 95 Rationale.

- Bob



  parent reply	other threads:[~2005-06-29 20:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-22 18:08 task time-out&abort e.coli
2005-06-22 18:40 ` Dmitry A. Kazakov
2005-06-23 10:11   ` e.coli
2005-06-23 10:59     ` Dmitry A. Kazakov
2005-06-22 19:44 ` Mark Lorenzen
2005-06-23  1:44 ` Steve
2005-06-23 15:26 ` e.coli
2005-06-23 17:01   ` e.coli
2005-06-24 11:42     ` Marius Amado Alves
2005-06-28 21:31       ` Robert A Duff
2005-06-29  0:32         ` Marius Amado Alves
2005-06-29 20:52   ` Robert A Duff [this message]
2005-07-18 16:11     ` Robert I. Eachus
replies disabled

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