在 Ada 中等待任务

发布于 2024-10-07 05:59:37 字数 48 浏览 4 评论 0原文

我有一个包含任务的程序。 所有任务结束后我必须做一些事情。 我怎样才能做到这一点?

I have a procedure with tasks in it.
I have to do something after the all of the tasks terminated.
How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦屿孤独相伴 2024-10-14 05:59:37

在内部块中声明任务:直到所有任务完成后,该块才会退出,ARM7.6.1(4)

with Ada.Text_IO; use Ada.Text_IO;
procedure After_Tasks is
begin
   Put_Line ("at the start");

   declare
      task T1;
      task T2;
      task body T1 is
      begin
         delay 1.0;
         Put_Line ("t1 done");
      end T1;
      task body T2 is
      begin
         delay 2.0;
         Put_Line ("t2 done");
      end T2;
   begin
      null;
   end;        -- block here until T1 & T2 are completed

   Put_Line ("at the end");
end After_Tasks;

Declare the tasks in an inner block: the block won't exit until all the tasks are complete, ARM7.6.1(4)

with Ada.Text_IO; use Ada.Text_IO;
procedure After_Tasks is
begin
   Put_Line ("at the start");

   declare
      task T1;
      task T2;
      task body T1 is
      begin
         delay 1.0;
         Put_Line ("t1 done");
      end T1;
      task body T2 is
      begin
         delay 2.0;
         Put_Line ("t2 done");
      end T2;
   begin
      null;
   end;        -- block here until T1 & T2 are completed

   Put_Line ("at the end");
end After_Tasks;
你的笑 2024-10-14 05:59:37

在不了解您实际想要完成的任务的情况下,完成此任务的一些尝试是:

  • 监视(轮询)每个待处理任务的 '终止 属性。
  • 在任务中实现“关闭”条目,这是每个任务执行的最后一件事。让您的“控制器”与每个任务的关闭条目会合,一旦所有任务都接受并完成了会合,无论出于何种意图和目的,您都可以得出结论,任务已全部终止。对于我们当中的迂腐者来说,我们可能会执行一个短暂的延迟(delay 0.0;),然后通过“Termerated”属性验证所有任务是否已终止,或者至少pragma Assert()代码>所以。

Without any knowledge of what you're actually trying to accomplish, a couple stabs at accomplishing this would be:

  • Monitor (poll) each pending task's 'Terminated attribute.
  • Implement a "Shutdown" entry in your task(s) that is the last thing each task performs. Have your "controller" rendezvous with each task's Shutdown entry and once all tasks have accepted and completed the rendezvous, for all intents and purposes you can conclude that the tasks have all terminated. For the pedantic among us, we might execute a short delay (delay 0.0;) and then verify via the 'Terminated attribute that all tasks are terminated, or at least pragma Assert() so.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文