home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!news.sei.cmu.edu!rmo
- From: rmo@sei.cmu.edu (Robert Ollerton)
- Subject: Re: Dynamic Task Creation/Control
- Message-ID: <1992Aug22.140034.17727@sei.cmu.edu>
- Sender: netnews@sei.cmu.edu (Netnews)
- Organization: Software Engineering Institute
- References: <1992Aug20.174857.3246@afit.af.mil>
- Date: Sat, 22 Aug 1992 14:00:34 GMT
- Lines: 116
-
- I encountered the problem of dynamic task creation/destruction in
- the development of the Ada Process-Oriented Simulation Library (APOSL).
- The essence of the APOSL solution is to encapsulate the task logic within
- a loop that stops and starts task execution.
- All tasks in this system are created through the evaluation of
- allocators declared in the outer scope of library-level packages. The
- following semi-code is a simplification of the this approach.
-
- Hope this helps.
-
- ------
-
- package Task_Pkg is
-
- type Task_Ptr is
- private;
-
- procedure Create
- ( The_Task : out Task_Ptr );
-
- procedure Destroy
- ( The_Task : in out Task_Ptr );
-
- procedure Entry_1
- ( The_Task : in Task_Ptr );
-
- procedure Entry_2;
- ( The_Task : in Task_Ptr );
-
- pragma Inline (Entry_1, Entry_2);
-
- private
-
- task body Reusable_Task is
- entry Start_Executing;
- entry Stop_Executing;
- entry Entry_1;
- entry Entry_2;
- end Reusable_Task;
-
- type Task_Ptr is
- access Reusable_Task;
-
- end Task_Pkg;
-
- package body Task_Pkg is
-
- Storage
- : Stack_Of_Task_Ptr;
-
- procedure Create
- ( The_Task : out Task_Ptr ) is
- New_Task
- : Task_Ptr;
- begin
- if Empty(Storage) then
- New_Task := new Example;
- else
- Pop(Storage,New_Task);
- end if;
- New_Task.Start_Executing;
- The_Task := New_Task;
- end Create;
-
- procedure Destroy
- ( The_Task : in out Task_Ptr ) is
- begin
- The_Task.Stop_Executing;
- Push(Storage,The_Task);
- The_Task := null;
- end Destroy;
-
- procedure Entry_1
- ( The_Task : in Task_Ptr ) is
- begin
- The_Task.Entry_1;
- end Entry_1;
-
- procedure Entry_2
- ( The_Task : in Task_Ptr ) is
- begin
- The_Task.Entry_2;
- end Entry_2;
-
- task body Reusable_Task is
- begin
- loop
- entry Start_Executing;
- loop
- select
- accept Stop_Executing;
- exit;
- or
- accept Entry_1;
- -- Task Entry Logic
- or
- accept Entry_2;
- -- Task Entry Logic
- end select;
- end loop;
- end loop;
- end Reusable_Task;
-
- end Task_Pkg;
-
- -----
-
- These opinions are my own and nobody else's.
-
- Robert Ollerton
- Navy Resident to SEI
- Naval Command, Control and Ocean Surveilance Center Research, Development
- Test and Evaluation Division
-
- ollerton@nosc.mil
- rmo@sei.cmu.edu
-