如果我们在 Ada 中有两个任务,并且如果我有一个延迟语句,无论是“延迟 0.0”还是“延迟 1.0”,是否会使该进程进入阻塞状态?或者流程状态在这里不适用?下面是一个简单的代码来说明我的问题:
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;
就进程状态而言,我正在谈论此图中所示的进程/线程状态:
最佳答案
根据Ada 2012引用手册部分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.
关于concurrency - 延迟语句是否使进程处于阻塞状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68971117/