Finalization of a record containing a task

From: Bj?rn (ssh9614_at_hotmail.com)
Date: 02/16/05


Date: 16 Feb 2005 12:35:30 -0800

I'm trying to implement a form of self modifying ADT, containing an
active task.

I would prefer that the user of the ADT not need to do any "extra"
operations on the ADT when the user is finished with it, rather have
the task terminate automatically when the type goes out of scope.

I do not see how I can manage this since the ADT does not seem to
finalize as long as the tasks have not terminated.

How can I solve this? Should I rather try a different approach?

Currently it looks something like this:

package PKG is
   type T_ADT is new Limited_Controlled with private
   ...
private
   task type T_Worker is
      entry Start;
      entry Stop;
      ...
   end task;
   
   procedure Initialize (T : in out T_ADT);
   procedure Finalize (T : in out T_ADT);

   type T_ADT is new Limited_Controlled with
      record
         X : Some_Type;
         Worker : T_Worker;
      end record;
end PKG;

package body PKG is
   task T_Worker is
      {Inner task of T_Worker}
   begin
      loop
         select
            accept Start;
         or
            accept Stop;
         or
            ...
         or
            delay until Some_Time;
         end select;
      end loop;
end PKG;

Best regards,
Björn