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=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8d9c008219fb2dce X-Google-Attributes: gid103376,public From: Mats Weber Subject: Re: Task deallocation Date: 1997/02/12 Message-ID: <3301EE04.688E@elca-matrix.ch>#1/1 X-Deja-AN: 218280645 References: <01bc185c$76beb9c0$829d6482@joy.ericsson.se> Content-Type: text/plain; charset=us-ascii Organization: ELCA Matrix SA Mime-Version: 1.0 Reply-To: Mats.Weber@elca-matrix.ch Newsgroups: comp.lang.ada X-Mailer: Mozilla 3.01 (Macintosh; I; PPC) Date: 1997-02-12T00:00:00+00:00 List-Id: > 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.