You have not described what you mean by "background".
Here is a simple Ada program where the "background" task runs as I think you want a background task to run.
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
task background;
task body background is
begin
for I in 1 .. 10 loop
Put_Line ("Background:" & I'Image);
delay 1.5;
end loop;
end background;
begin
for I in 1 .. 10 loop
Put_Line ("Main" & I'Image);
delay 1.0;
end loop;
end Main;
A sample output from this program is:
Main 1
Background: 1
Main 2
Background: 2
Main 3
Background: 3
Main 4
Main 5
Background: 4
Main 6
Background: 5
Main 7
Main 8
Background: 6
Main 9
Background: 7
Main 10
Background: 8
Background: 9
Background: 10
The main task clearly works independently of the background task. Since both tasks are in the same process the process must not terminate before both tasks terminate.
If you want the main task to wait for the completion of the background task before it terminates, the background task must be created in an inner block of the main task.
with Ada.Text_IO; use Ada.Text_IO;
procedure joined_task is
begin
-- create an inner block
declare
task background;
task body background is
begin
for I in 1 .. 10 loop
Put_Line ("Background:" & I'Image);
delay 1.5;
end loop;
end background;
begin
null;
end;
for I in 1 .. 10 loop
Put_Line ("Main:" & I'Image);
delay 1.0;
end loop;
end joined_task;
The output of this program is:
Background: 1
Background: 2
Background: 3
Background: 4
Background: 5
Background: 6
Background: 7
Background: 8
Background: 9
Background: 10
Main: 1
Main: 2
Main: 3
Main: 4
Main: 5
Main: 6
Main: 7
Main: 8
Main: 9
Main: 10
The main task waited for the background task to complete before executing its loop.
In the first example both tasks executed in an overlapping manner, while the second example demonstrated how the main task waited for completion of its inner block before proceeding. The second example is functionally similar to using the join command in Java or in C or C++ thread libraries.