9.6 Delay Statements, Duration, and Time
This Reference Manual output has not been verified, and may contain omissions or errors. Report any problems on the tracking issue
[ A delay_statement
is used to block further execution until a specified expiration time is reached. The expiration time can be specified either as a particular point in time (in a delay_until_statement
), or in seconds from the current time (in a delay_relative_statement
). The language-defined package Calendar provides definitions for a type Time and associated operations, including a function Clock that returns the current time. ]
Syntax
2delay_statement
::=
delay_until_statement
| delay_relative_statement
3
delay_until_statement
::=
delay until delay_expression
;
4
delay_relative_statement
::=
delay delay_expression
;
Name Resolution Rules
5The expected type for the delay_expression
in a delay_relative_statement
is the predefined type Duration. The delay_expression
in a delay_until_statement
is expected to be of any nonlimited type.
Legality Rules
6/3There can be multiple time bases, each with a corresponding clock, and a corresponding time type. The type of the delay_expression
in a delay_until_statement
shall be a time type — either the type Time defined in the language-defined package Calendar (see below), the type Time in the package Real_Time (see D.8), or some other implementation-defined time type.
Any implementation-defined time types.
Static Semantics
7[There is a predefined fixed point type named Duration, declared in the visible part of package Standard;] a value of type Duration is used to represent the length of an interval of time, expressed in seconds. [The type Duration is not specific to a particular time base, but can be used with any time base.]
A value of the type Time in package Calendar, or of some other time type, represents a time as reported by a corresponding clock.
The following language-defined library package exists:
package Ada.Calendar
with Nonblocking, Global => in out synchronized is
type Time is private;
11/2
subtype Year_Number is Integer range 1901 .. 2399;
subtype Month_Number is Integer range 1 .. 12;
subtype Day_Number is Integer range 1 .. 31;
subtype Day_Duration is Duration range 0.0 .. 86_400.0;
A range of 500 years was chosen, as that only requires one extra bit for the year as compared to Ada 95. This was done to minimize disruptions with existing implementations. (One implementor reports that their time values represent nanoseconds, and this year range requires 63.77 bits to represent.)
function Clock return Time;
13
function Year (Date : Time) return Year_Number;
function Month (Date : Time) return Month_Number;
function Day (Date : Time) return Day_Number;
function Seconds(Date : Time) return Day_Duration;
14
procedure Split (Date : in Time;
Year : out Year_Number;
Month : out Month_Number;
Day : out Day_Number;
Seconds : out Day_Duration);
15
function Time_Of(Year : Year_Number;
Month : Month_Number;
Day : Day_Number;
Seconds : Day_Duration := 0.0)
return Time;
16
function "+" (Left : Time; Right : Duration) return Time;
function "+" (Left : Duration; Right : Time) return Time;
function "-" (Left : Time; Right : Duration) return Time;
function "-" (Left : Time; Right : Time) return Duration;
17
function "<" (Left, Right : Time) return Boolean;
function "<="(Left, Right : Time) return Boolean;
function ">" (Left, Right : Time) return Boolean;
function ">="(Left, Right : Time) return Boolean;
18
Time_Error : exception;
19
private
... -- not specified by the language
end Ada.Calendar;
Dynamic Semantics
20For 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 time base associated with relative delays.
Rounding up to the next clock tick means that the reading of the delay-relative clock when the delay expires should be no less than the current reading of the delay-relative clock plus the specified duration.
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.
For a delay_relative_statement
, this case corresponds to when the value of the delay_expression
is zero or negative.
Even though the task is not blocked, it might be put back on the end of its ready queue. See D.2, “Priority Scheduling