comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Termination of periodic tasks
Date: Tue, 17 Jun 2014 15:00:52 -0500
Date: 2014-06-17T15:00:52-05:00	[thread overview]
Message-ID: <lnq6pk$enn$1@loke.gir.dk> (raw)
In-Reply-To: k4bw956nq1hk.1fbqgpp5xu777$.dlg@40tude.net

"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message 
news:k4bw956nq1hk.1fbqgpp5xu777$.dlg@40tude.net...
...
> Thus per design there is no way to make a non-trivial library-level task 
> to
> complete without means outside the library level. Either some OS-specific
> stuff or an explicit action/declaration in a nested scope is required.

Actually, there is a way, at least if you want to ensure that the program 
cleans itself up properly. We invented it for Claw, and I put it into the 
ACATS so it's pretty certain that all compilers support it.

The trick is to use Ada.Task_Identification to find out whether the 
environment task is trying to exit.

    if not Is_Callable(Environment_Task) then
        return; -- Exit this task.
   end if;

Is_Callable will only be False for the environment task if the main 
subprogram has exited and we're waiting for library-level tasks to complete. 
In that case, we want to kill off this task. (Note: Not all Ada 95 compilers 
did this at the time, some always returned true from it no matter what. But 
that would fail ACATS test CXC7004 in modern compilers, so it's unlikely 
that many get this wrong. One might want to look at that ACATS test for a 
complete example of the method.)

It can be clunky to get this into the task somewhere; it works best if the 
task is actively polling (as the message loop task in Claw is always doing).

Note: function Environment_Task was added to the package in Ada 2012. For 
earlier Ada, one needs to have the elaboration of the package containing the 
task squirrel away the task id:

   Environment_Task_Id : constant Task_Id := Current_Task;

                                               Randy.




  reply	other threads:[~2014-06-17 20:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-15 10:10 Termination of periodic tasks Natasha Kerensikova
2014-06-15 12:11 ` Dmitry A. Kazakov
2014-06-15 15:23 ` J-P. Rosen
2014-06-16 13:54   ` Natasha Kerensikova
2014-06-17 20:14     ` Charles H. Sampson
2014-06-18  7:32       ` Dmitry A. Kazakov
2014-06-15 16:54 ` Jeffrey Carter
2014-06-16 14:02   ` Natasha Kerensikova
2014-06-16 15:08     ` Dmitry A. Kazakov
2014-06-16 17:08     ` Jeffrey Carter
2014-06-17  6:57       ` Natasha Kerensikova
2014-06-17  7:37         ` Dmitry A. Kazakov
2014-06-17  7:47           ` Natasha Kerensikova
2014-06-17  8:45             ` Dmitry A. Kazakov
2014-06-17  9:00               ` Natasha Kerensikova
2014-06-17 12:55                 ` Dmitry A. Kazakov
2014-06-17 14:51                   ` J-P. Rosen
2014-06-17 16:44                     ` Dmitry A. Kazakov
2014-06-17 20:00                       ` Randy Brukardt [this message]
2014-06-17 20:16                         ` Jeffrey Carter
2014-06-17 21:30                         ` Simon Wright
2014-06-17 12:02         ` Jacob Sparre Andersen
2014-06-17 19:32           ` Natasha Kerensikova
2014-06-17 17:53         ` Jeffrey Carter
2014-06-17 20:03           ` Randy Brukardt
replies disabled

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