comp.lang.ada
 help / color / mirror / Atom feed
From: anisimkov@yahoo.com (Dmitriy Anisimkov)
Subject: Re: Basic program with tasks goes out of memory
Date: 6 Aug 2004 21:04:36 -0700
Date: 2004-08-06T21:04:36-07:00	[thread overview]
Message-ID: <413e860a.0408062004.6cd54bf9@posting.google.com> (raw)
In-Reply-To: 5ad0dd8a.0408050655.355fa926@posting.google.com

wojtek@power.com.pl (Wojtek Narczynski) wrote in message 
>
> Any idea why this program (extracted from AdaSockets example)
> eventually eats up all RAM? Runtime leak or my ignorance?

I think the only way to do not leak memory on dynamically allocated
tasks,
is to have a task for deallocate terminated tasks. And each
dynamically allocated task have to pass its pointer to the Destructor
before termination.

The Destructor have to be like that.
-------------------------------
   task body Destructor is
      Rf : Relay_Access;
      procedure Free is new Ada.Unchecked_Deallocation (Relay,
Relay_Access);
   begin
      loop
         select
            accept Free_Task (R : Relay_Access) do
               Rf := R;
            end Free_Task;
         end select;

         loop
            exit when Rf'Terminated;
            delay 0.001;
         end loop;

         Free (Rf);
      end loop;
   exception when E : others =>
      Unexpected (E, "Destructor");
   end Destructor;
-------------------------
The complete application with task Destructor usage is in the

http://www.ada-ru.org/src/relay.adb

It has a same as tcprelay.adb (from AdaSockets) functionality, but
with dynamically created task deallocation.

It would be good to have a method to wait until task termination like
on entry call. Maybe something like that.
----------------------------------
   task body Destructor is
      Rf : Relay_Access;
      procedure Free is new Ada.Unchecked_Deallocation (Relay,
Relay_Access);
   begin
      loop
         select
            accept Free_Task (R : Relay_Access) do
               Rf := R;
            end Free_Task;
         end select;

         select
            Rf'Wait_Termination;
         or delay 10.0;
            --  Could not wait more.
            null;
         end loop;

         Free (Rf);
      end loop;
   exception when E : others =>
      Unexpected (E, "Destructor");
   end Destructor;
-------------------------



      parent reply	other threads:[~2004-08-07  4:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-05 14:55 Basic program with tasks goes out of memory Wojtek Narczynski
2004-08-05 15:18 ` Dmitry A. Kazakov
2004-08-05 16:13 ` Marc A. Criley
2004-08-06  8:54   ` Jano
2004-08-06  9:53     ` Jean-Pierre Rosen
2004-08-06 11:23       ` Jano
2004-08-06 15:26       ` Wojtek Narczynski
2004-08-06 10:57   ` Wojtek Narczynski
2004-08-05 18:32 ` Jim Rogers
2004-08-07  4:04 ` Dmitriy Anisimkov [this message]
replies disabled

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