comp.lang.ada
 help / color / mirror / Atom feed
From: Mats Weber <Mats.Weber@elca-matrix.ch>
Subject: Re: Task deallocation
Date: 1997/02/12
Date: 1997-02-12T00:00:00+00:00	[thread overview]
Message-ID: <3301EE04.688E@elca-matrix.ch> (raw)
In-Reply-To: 01bc185c$76beb9c0$829d6482@joy.ericsson.se


> I am doing a server-task that dynamically allocates sub-tasks to handle
> individual requests. I want the sub-tasks to use a terminate alternative
> so that they terminate when the server-task is terminated. My problem is
> how to reclaim the storage for the sub-tasks. One possible alternative is
> to have a linked list of the sub-tasks outside of the-server task and then
> scan this list of sub-tasks for terminated tasks and delete them,
> recursively
> until the list is empty. This code looks a bit on the heavy side and maybe
> there is an easier way to reclaim the storage used by these tasks.
> 
> Anybody have any good suggestions of a better alternative to the solution I
> described above? Any suggestions are welcome.
> 
> /jonas
> 
> PS If the sub-task type were defined inside the server-task then it should
>    be possible for the Ada RT to automagically free the sub-tasks after the
>    the termination of the server-task since they cannot be referenced by
>    any other entity. I have read the Ada RM but I cannot find anything on
>    this topic (except that it is an error to free a non-terminated task). DS

You can arrange for the server to be the master of the sub-tasks (even
if the sub-task type is declared in another library package) in the
following way:

package Subtasks is
   task type T is
      entry E;
      -- has a terminate alternative.
   end T;
end Subtasks;

with Subtasks;

procedure Server is

   type Subtask_Access is access Subtasks.T;
      -- Tasks created by allocators of this access type
      -- will have Server as master.

begin
   ... := new Subtasks.T;
end Server;

When the server finishes, it will wait for all subtasks to terminate,
and thus their terminate alternatives will be open. If one or more of
the subtasks are not ready to terminate, then Server will not exit.
Note: Server can be the main program, or it can be called from another
program unit.




  reply	other threads:[~1997-02-12  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-11  0:00 Task deallocation Jonas Nygren
1997-02-12  0:00 ` Mats Weber [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-02-23  0:00 Jonas Nygren
1997-02-28  0:00 ` Mats Weber
1997-03-01  0:00   ` Robert Dewar
1997-03-03  0:00     ` Mats Weber
1997-03-04  0:00       ` Robert Dewar
replies disabled

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