T. Tasks - JulTob/Ada GitHub Wiki
Tasks happen at the same time and simultaniusly to the main program.
with Text_IO; Use Text_IO;
Procedure test is
Task drink;
-- One task, called bird
Task Body drink is
speed : duration := 1.0;
i : Integer := 100;
Begin
Loop
put_line("There's " & Integer'Image(i) & " bottles in the wall");
put_line("I drink one bottle.");
i := i - 1;
Delay speed; -- slow it down so you can watch the bird move
end loop;
End Drink;
Task eat;
-- One task, called bird
Task Body Eat is
speed : duration := 5.0;
i : Integer := 20;
Begin
Loop
put_line("There's " & Integer'Image(i) & " eggs in the shelf");
put_line("I eat one egg.");
i := i - 1;
Delay speed; -- slow it down so you can watch the bird move
end loop;
End Eat;
Begin
-- The tasks are activated in parallel with the main prog.
Null;
-- The main program has nothing to do - it just waits
-- for the task to finish.
End test;
The output of this program will mix output from both tasks.
-- terminate this process
Ada.Task_Identification.Abort_Task(
Ada.Task_Identification.Current_Task);