Ich versuche, alle Prozeduren in einem Array gleichzeitig aber ohne Erfolg ausgeführt werden. Ich kann sie nacheinander ausführen:Ada gleichzeitige Ausführung von Array von Prozedur Zeigern
with ada.text_io; -- Tell compiler to use i/o library
use ada.text_io; -- Use library routines w/o fully qualified names
with Ada.Numerics.Float_Random; -- Use numerics for the random generation
use ada.Numerics.Float_Random;
procedure Main is
type Callback_Procedure is access procedure; -- Type that contains a procedure pointer
type arr is array (Natural range <>) of Callback_Procedure; -- Array starting from 0 toi infinite of procedure pointers
seed : Generator; -- Seed for the generator
-- Procedure that will execute "concurrently" the procedures passed in the array
procedure EjecutarConcurrentemente(procs : in arr) is
begin
for index in 0 .. procs'Last loop
procs(index).all; -- .all dereferences the pointer so it is the procedure itself (the value pointed by the pointer)
end loop;
end EjecutarConcurrentemente;
function rndDelay return Duration is
num : Duration;
begin
num := Duration(Random(seed));
return num * Duration(10);
end ;
procedure test0 is
begin
delay rndDelay;
put("test0");
New_Line;
end test0;
procedure test1 is
begin
delay rndDelay;
put("test1");
New_Line;
end test1;
procedure test2 is
begin
delay rndDelay;
put("test2");
New_Line;
end test2;
procedure test3 is
begin
delay rndDelay;
put("test3");
New_Line;
end test3;
procedure test4 is
begin
delay rndDelay;
put("test4");
New_Line;
end test4;
procedure test5 is
begin
delay rndDelay;
put("test5");
New_Line;
end test5;
procs : arr(0..5);
begin
Reset(seed);
procs(0) := test0'Access;
procs(1) := test1'Access;
procs(2) := test2'Access;
procs(3) := test3'Access;
procs(4) := test4'Access;
procs(5) := test5'Access;
EjecutarConcurrentemente(procs);
end Main;
Das Hauptverfahren Körper auffüllt ein Array mit 6 Prozeduren deklarierten vor und die Anrufe EjecutarConcurrentemente mit diesem Array und es muss dieses neue Verfahren sein, die gleichzeitig die Array-Prozeduren auszuführen hat.
Ich wurde angewiesen, die Task-Funktionen zu verwenden, und der TestX muss Prozeduren ohne Argumente sein.
Hoffe, ich habe es gut erklärt, auch ich habe gerade mit Ada begonnen, also wird der Code höchstwahrscheinlich schlecht gebildet sein.
Danke.
Warum würde die Anzahl der Argumente für die testX-Prozeduren die Verwendung von Aufgaben verhindern? – egilhh
"Gleichzeitig" mit was? Das Hauptprogramm? (Easy-ish), einander? (Schwierig). –
@egilhh Ich sage das nicht, ich sage nur, dass es eine Voraussetzung ist –