comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: deallocation tasks
Date: 2000/05/03
Date: 2000-05-03T00:00:00+00:00	[thread overview]
Message-ID: <wccbt2nln7v.fsf@world.std.com> (raw)
In-Reply-To: 39102BF9.584EB022@icn.siemens.de

Alfred Hilscher <Alfred.Hilscher@icn.siemens.de> writes:

> What I want do is this: I have a loop that reads input and processes it.
> If the input is something that would require long runtime, I want create
> a new task so that it can run in background. But if the task terminates
> I think I should free the (heap) memory.
> 
> My code would look someting like this:
> 
> task type t is ...
> 
> type a_t  is access t;
>  
> n_t : a_t;
> ...
> 
> loop
>  -- get input
> 
>   if  -- input requires less time
>   then
>     -- consume it
>   else -- input requires much time, start background task
>     n_t := new a_t(input);  -- memory allocated here should be
> deallocated after task termination
>   end if;
> end loop;
> 
> 
> Any suggestions how to 'DEALLOCATE' the memory ? There can be more than
> one task at a time. Any other ideas ?

Read the RM rules about Unchecked_Deallocation.  If the task has no
discriminants, then it's safe to call Unchecked_Deallocation before
the task is terminated.  (Which seems strange to me.)  If it has
discriminants, then don't do that.

You can find out whether a task is terminated using 'Terminated, but
that generally requires some sort of busy waiting.

You could also consider having a single task, or a pool of several
tasks, that gets reused for each input-processing.  You probably don't
want to create 1_000_000 tasks if the input has 1_000_000 lines.

- Bob




  reply	other threads:[~2000-05-03  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-05-03  0:00 deallocation tasks Alfred Hilscher
2000-05-03  0:00 ` Robert A Duff [this message]
2000-05-04  0:00   ` Pascal Obry
2000-05-04  0:00     ` Robert A Duff
2000-05-05  0:00       ` Alfred Hilscher
replies disabled

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