Fun with Tasking



Below is sample code I made representing something I wanted to do with
a program, of course it doesn't work quite the way I would like.
Hopefully this sample doesn't cause eye (or brain) injury, it is more
symbolic than useful - the procedure "Exec" is, of course, really a
package (rather, several similar packages).

The problem is, how to "transport" a task? As seen in the sample
below, I would like to use just a single address in the Control_Block
type, but it's never that simple, is it? In actuality, how I get this
program in its full incarnation to work is to define the "test_task"s
in the acc_add_test part of the program. I really don't like doing
this, as I mentioned, "exec" is representative of a family of several
different packages. I would like the task definition to be local to
the "exec" pacakage(s), not all kludged together in acc_add_test,
which then requires all sorts of (ideally private) types being moved
out of the local "exec" packages into acc_add_test and then the
Control_Block record now has nearly a dozen different task pointers
stuffed into it, only one of which is going to be used at any given
time.

One last caveat, the Acc_Add_Test program should have *no* visibility
into the "exec" procedure/package. The "exec" package(s), in fact,
"push" their procedures into the main program. So is there something
simple I'm having a brain fart over in missing here, or is a complete
re-architecture required here?

with Text_Io;
with System;
with System.Address_To_Access_Conversions;

procedure Acc_Add_test is

Exec_Count : constant Natural := 10;

type Control_Block is
record
Task_Addr : System.Address;
end record;

type Mode_Type is (preprocess, process);

procedure Exec (Mode : in Mode_Type;
Cntl : in out Control_Block) is

task type Test_Task is
entry Start (Addr : System.Address);
entry Complete;
end Test_Task;

package Convert is new System.Address_To_Access_Conversions
(Test_Task);
use Convert;

task body Test_Task is
Task_Ptr : Convert.Object_Pointer := null;
Count : Natural := 0;
begin
loop
begin
select
accept Start (Addr : System.Address) do
Task_Ptr := Convert.To_Pointer (Addr);
end Start;

or
accept Complete do
Count := Count + 1;
end Complete;
if Count = Exec_Count then
Text_Io.Put_Line ("Completed All Tasks");
abort Task_Ptr.all;
end if;
end select;
end;
end loop;
end Test_Task;

begin
case Mode is
when Preprocess =>
declare
Task_Ptr : Convert.Object_Pointer;
Address : System.Address;
begin
Task_Ptr := new Test_Task;
Address := Convert.To_Address (Task_Ptr);
Task_Ptr.Start (Address);
Cntl.Task_Addr := Address;
end;

when Process =>
declare
Task_Ptr : Convert.Object_Pointer;
begin
Task_Ptr := Convert.To_Pointer (Cntl.Task_Addr);
Task_Ptr.Complete;
end;
end case;
end Exec;

Controls : Control_Block;

begin
Exec (Preprocess, Controls);
for I in 1 .. Exec_Count loop
Exec (Process, Controls);
end loop;
end Acc_Add_Test;

Thanks for any input!

.



Relevant Pages

  • Re: Mixed Simulation of Design (VHDL and Verilog)
    ... Dependency exists between package a and package BODY b ... SUBTYPE c_range IS natural RANGE a'RANGE; ... c_loop: ... Segmentation violation if a subtype is used as an index ...
    (comp.lang.vhdl)
  • Looping through files for importing
    ... I understand how to loop through all files in a folder using VB/VBA, so I can manage that if I save the package as a VB File. ... one month and conveniently has the month end date in the file name, so I can populate the field by extracting the date from the file ... then in my Transform Data Task, I would have an ActiveX Script transformation assigning that date global variable to the MEDate ...
    (microsoft.public.sqlserver.dts)
  • Re: DTS Workflow Question
    ... >I am using SQL Server 2000 and I am writing a DTS package that loops ... >Script handling the loop routine. ... You could duplicate the ActiveX Script to restart the loop, ... Darren Green (SQL Server MVP) ...
    (microsoft.public.sqlserver.dts)
  • Re: Incremental statistics functions
    ... Package for simple statistics and error calculation. ... Rms ... Exp: in Ada.Text_io.Field) is ... for I in Values'range loop ...
    (comp.lang.ada)
  • Re: Oracle procedure raises exception but looks to be successful from DBI
    ... I sort if expected that for the exec it is usualy only used withing SP ... Either the use who is calling the SP dose not have execute permission for the package or something in the package or the present state of the package is stopping you from executing it. ... The fact that DBD is returning the error from Oracle usually means that DBD is running correctly. ...
    (perl.dbi.users)