comp.lang.ada
 help / color / mirror / Atom feed
From: "Jonas Nygren" <ehsjony@ehs.ericsson.se>
Subject: Deallocating Task objects
Date: 1997/02/15
Date: 1997-02-15T00:00:00+00:00	[thread overview]
Message-ID: <01bc1b53$fb0251c0$829d6482@joy.ericsson.se> (raw)



I sent out a question to c.l.a about how to reclaim memory for tasks
that are dynamically allocated. Since then I have been trying to find 
some 'nice' way of doing this.

I have identified one sentence in the Ada RM that seems to provide
some sort of automatic storage reclamation. The sentence is found in 
13.11(18) and reads:

"If Storage_Size is specified for an access type, then the Storage_Size 
 of this pool is at least that requested, and the storage for the pool 
 is reclaimed when the master containing the declaration of the access 
 type is left."

This seems to provide some sort of 'garbage collection'. One have
to give an upper bound on the number of allocatable objects but this is
quite acceptable for my code.

I wonder if somebody can confirm that my interpretation of this sentence
is correct. Below I have attached a small tasking example with one
Main_Task that dynamically allocates Sub_Tasks and I want to be absolutely 
sure that the storage used for the Sub_Tasks have been reclaimed when the
Main_Task instance, A_Main_Task, goes out of scope.

Have I interpreted the 13.11(18) sentence correctly? Is the construct 
portable between different Ada compilers?

/jonas

PS of course I could have defined an array of Sub_Tasks instead but then
   there would have been the added complexity of synchronizing the
Main_Task's
   stack size with the number of allocated Sub_Tasks. DS

PPS I have tried this with Gnat 3.09 for NT and Win95 and it will only
handle
    a maximum of 57 Sub_Tasks. With 58, or more, Sub_Tasks it will just
hang 
    in the allocator, without any errors. I will report this bug to ACT.
DDS

-- code follows

with Text_IO;
procedure Test is
   task type Main_Task (Max_Sub_Tasks : Positive);

   task body Main_Task is

      task type Sub_Task is
         entry Dummy;
      end Sub_Task;

      type Sub_Task_Ref is access Sub_Task;
      for Sub_Task_Ref'Storage_Size use Max_Sub_Tasks * Sub_Task'Size; --
13.11(18)

      task body Sub_Task is
      begin
         loop
            select
               accept Dummy;
            or
               terminate;
            end select;
         end loop;
      end Sub_Task;

      A_Sub_Task : Sub_Task_Ref;
   begin
      for I in 1..Max_Sub_Tasks loop
         A_Sub_Task := new Sub_Task;
	  Text_IO.Put_Line(Integer'Image(I));
      end loop;

      delay 1.0;
   end Main_Task;
begin
   declare
      A_Main_Task : Main_Task(1000);
   begin
      null;
   end;
   -- at this point all storage allocated for Sub_Task objects
   -- in A_Main_Task will have been reclaimed
end Test;





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

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-02-15  0:00 Jonas Nygren [this message]
1997-02-15  0:00 ` Deallocating Task objects Robert Dewar
1997-02-17  0:00 ` Mats Weber
1997-02-18  0:00   ` Robert L. Spooner
1997-02-18  0:00     ` Robert A Duff
1997-02-18  0:00       ` Robert Dewar
1997-02-20  0:00         ` Norman H. Cohen
1997-02-21  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