Lawrence D'Oliveiro
2024-06-30 08:06:35 UTC
with Ada.Text_IO;
use Ada;
procedure parasieve1 is
task type child is
entry next_int(i : integer);
end child;
subtype offspring is child;
-- need another name because "child" within child refers to
-- current task, not to the type
task body child is
my_prime : integer;
subchild : access offspring;
begin
accept next_int(i : integer) do
my_prime := i;
Text_IO.Put_line(integer'image(my_prime));
end next_int;
subchild := new offspring;
loop
accept next_int(i : integer) do
if i mod my_prime /= 0 then
subchild.next_int(i);
end if;
end next_int;
end loop;
end child;
first_child : child;
i : integer;
begin -- parasieve1
i := 1;
loop
i := i + 1;
first_child.next_int(i);
end loop;
end parasieve1;
use Ada;
procedure parasieve1 is
task type child is
entry next_int(i : integer);
end child;
subtype offspring is child;
-- need another name because "child" within child refers to
-- current task, not to the type
task body child is
my_prime : integer;
subchild : access offspring;
begin
accept next_int(i : integer) do
my_prime := i;
Text_IO.Put_line(integer'image(my_prime));
end next_int;
subchild := new offspring;
loop
accept next_int(i : integer) do
if i mod my_prime /= 0 then
subchild.next_int(i);
end if;
end next_int;
end loop;
end child;
first_child : child;
i : integer;
begin -- parasieve1
i := 1;
loop
i := i + 1;
first_child.next_int(i);
end loop;
end parasieve1;