开发者

Wait for tasks in Ada

I have a procedure with tasks in it. I have to do something after the all of the tasks term开发者_运维技巧inated. How can I do that?


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;


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜