From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,622a39829f542d91 X-Google-Attributes: gid103376,public From: Robert A Duff Subject: Re: deallocation tasks Date: 2000/05/03 Message-ID: #1/1 X-Deja-AN: 618704238 Sender: bobduff@world.std.com (Robert A Duff) References: <39102BF9.584EB022@icn.siemens.de> Organization: The World Public Access UNIX, Brookline, MA Newsgroups: comp.lang.ada Date: 2000-05-03T00:00:00+00:00 List-Id: Alfred Hilscher 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