Tasks

Parallelism

Tasking

It's patently evident that a computer program or application can benefit from a non-sequential treatment of the orders given.

A chat program has to listen at the same time at the chatroom and to the keyboard, while printing all new messages from the room.

These parallel threats of orders are called Tasks in Ada.

Tasks are processes that run simultaneously and independently. If one crashes the rest can keep running.

Communication

The main concern when operating highly independent processes is to communicate among them.

For this reason they are usually part of a super-process that allows communications. Then, in other programming languages, they are equivalent to threats. In the context of the Operating System, they are called processes (duh).

Task Syntax

As any process, a task needs a specification and a body.

with Ada.Text_IO;

procedure Hello_World is

 --Specification of nested task
 task Hi;
 --Body of nested task
 task body Hi is
 begin
  Ada.Text_IO.Put_Line("Hello World of Tasks");
 end Hi;

begin --Hello World
   Ada.Text_IO.Put_Line("Don't look at me. I'm not a task");
end Hello_World;

Note the nested task runs as soon as the main program starts. Also, the main program will not return until the task is over.

The task can also access the elements of the nesting process (included tasks inside tasks).

time control

Synchronization

Tasks usually need to organize themselves on time.

Some utilities of tha Ada Language can be used for this.

Delay

As you may think, it produces a time delay.

Delays send the process to the process queue, so it might be more than the time specified.

delay 10.0; --seconds