Stacking_Flow
Stacking_Flow

Reputation: 125

Does the Delay Statement Place the Process in a Blocked State?

If we have two tasks in Ada, and if I had a delay statement, whether that's a "delay 0.0" or "delay 1.0", does that put that process into the blocked state? Or do the process states not apply here? The following is a simple code to illustrate my question:

with Ada.Text_IO; use Ada.Text_IO;

procedure Two_Tasks is

     task Task_1;
     task Task_2;

     task body Task_1 is
     begin
      for I in 1 .. 10 loop
         Put_Line ("Visited task 1, iteration number" & Integer'Image (I));
         delay 0.0;
      end loop;
     end Task_1;
  
     task body Task_2 is
     begin
      for I in 1 .. 10 loop
         Put_Line ("Visited task 2, iteration number" & Integer'Image (I));
      end loop;
     end Task_2;

begin
   Put_Line ("Visited the main task");
end Two_Tasks;

In terms of the process states, I am talking about the process/thread state shown in this diagram:

enter image description here

Upvotes: 2

Views: 146

Answers (1)

Jim Rogers
Jim Rogers

Reputation: 5031

According to Ada 2012 Reference Manual section 9.6:

For the execution of a delay_statement, the delay_expression is first evaluated. For a delay_until_statement, the expiration time for the delay is the value of the delay_expression, in the time base associated with the type of the expression. For a delay_relative_statement, the expiration time is defined as the current time, in the time base associated with relative delays, plus the value of the delay_expression converted to the type Duration, and then rounded up to the next clock tick. The time base associated with relative delays is as defined in D.9, “Delay Accuracy” or is implementation defined.

The task executing a delay_statement is blocked until the expiration time is reached, at which point it becomes ready again. If the expiration time has already passed, the task is not blocked.

Upvotes: 5

Related Questions