预期的私人类型“Ada.Real_Time.Time_Span”

时间:2018-05-01 07:57:44

标签: concurrency task ada

我有以下任务组:

with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
with Ada.Task_Identification; use Ada.Task_Identification;

package body pkg_task is
    task body task_t is
        activationTime : Time_Span := 1; -- 1 second
        period : Time_Span := 2; -- 2000 milliseconds
        computingTime : Time_Span := 1; -- 1000 milliseconds
        activeWaiting : Integer;
        startingTime : Time;
    begin
        delay To_Duration(activationTime);

        startingTime := Clock;

        while (Clock - startingTime) < computingTime loop
            activeWaiting := activeWaiting + 1;

            Put_Line("Task(" & Image(Current_Task) & "): Internal variable: " & Integer'Image(activeWaiting));

            if (period - (Clock - startingTime)) < computingTime then
                delay To_Duration(period - (Clock - startingTime));
            end if;
        end loop;
    end task_t;
end pkg_task;

编译时,我得到了上述错误:

gcc-7 -c pkg_task.adb
pkg_task.adb:8:47: expected private type "Ada.Real_Time.Time_Span"
pkg_task.adb:8:47: found type universal integer
pkg_task.adb:9:39: expected private type "Ada.Real_Time.Time_Span"
pkg_task.adb:9:39: found type universal integer
pkg_task.adb:10:46: expected private type "Ada.Real_Time.Time_Span"
pkg_task.adb:10:46: found type universal integer

问题是我对这种语言很陌生,我对此并不了解。事实上,我发现它有点复杂,我在互联网上找不到太多信息。

1 个答案:

答案 0 :(得分:3)

由于Time_Span是私有类型,因此不会自动转换文字。尝试:

To_Time_Span (1.0)

此外,由于To_Time_Span的参数是实数类型(持续时间),因此需要小数部分。 Ada不会让你在没有明确转换的情况下混合整数和真实类型。