concurrency - 延迟语句是否使进程处于阻塞状态?

标签 concurrency process state ada

如果我们在 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;

就进程状态而言,我正在谈论此图中所示的进程/线程状态:

enter image description here

最佳答案

根据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/

相关文章:

concurrency - 高吞吐量写入 Java 8 并发中的变量?

java - 为什么 InputStreamReader 不实时读取进程的输出?

machine-learning - 近端策略优化中的状态可以包含历史吗?

linux - 在谷歌可抢占实例上被抢占时如何保存状态?

用于生成 ConcurrentModificationException 的 Java 示例代码

java - 当不再有线程持有某个对象时,如何从 ConcurrentHashMap 中删除项目?

java - 如何使用正确的 run() 方法实现来保持 CopyOnWriteArrayList 的线程安全?

android - SQLite 数据库被锁定?

c - 如何从子进程中终止程序?

javascript - $state.go 从我当前的状态到当前的状态是否会触发相关事件?