1. with Ada.Text_IO;  use Ada.Text_IO; 
  2. with Ada.Calendar; use Ada.Calendar; 
  3.  
  4. procedure Synchronize is 
  5.  
  6.    Start_Up_Time : constant Time := Clock; 
  7.  
  8.    No_Of_Tasks : constant Positive := 2; 
  9.    subtype Task_Range is Positive range 1 .. No_Of_Tasks; 
  10.  
  11.    procedure Put_Line_w_Time (S : String) is 
  12.  
  13.    begin 
  14.       Put_Line ("At" & Duration'Image (Clock - Start_Up_Time) & " s : " & S); 
  15.    end Put_Line_w_Time; 
  16.  
  17.    procedure Put_Line_w_Time_n_Task_Id (Id : Task_Range; S : String) is 
  18.  
  19.    begin 
  20.       Put_Line_w_Time ("Task" & Task_Range'Image (Id) & " " & S); 
  21.    end Put_Line_w_Time_n_Task_Id; 
  22.  
  23.    task type Pinger is 
  24.  
  25.       entry Hand_over_Id (Given_Id : Task_Range); 
  26.       entry Last_Sync; 
  27.  
  28.    end Pinger; 
  29.  
  30.    task body Pinger is 
  31.  
  32.       Id : Task_Range; 
  33.  
  34.    begin 
  35.       Put_Line_w_Time ("Task ? is waiting for a ""Hand_over_Id"" rendezvous"); 
  36.       accept Hand_over_Id (Given_Id : Task_Range) do 
  37.          Id := Given_Id; 
  38.          Put_Line_w_Time_n_Task_Id (Id, "in a ""Hand_over_Id"" rendezvous"); 
  39.       end Hand_over_Id; 
  40.       Put_Line_w_Time_n_Task_Id (Id, "after a ""Hand_over_Id"" rendezvous"); 
  41.  
  42.       for i in 1 .. 4 loop 
  43.          Put_Line_w_Time ("Task" & Positive'Image (Id) & " active."); 
  44.          delay Duration (Id); 
  45.       end loop; 
  46.  
  47.       Put_Line_w_Time_n_Task_Id (Id, "waiting for a ""Last_Sync"" rendezvous"); 
  48.       accept Last_Sync do 
  49.          Put_Line_w_Time_n_Task_Id (Id, "in a ""Last_Sync"" rendezvous"); 
  50.       end Last_Sync; 
  51.       Put_Line_w_Time_n_Task_Id (Id, "after a ""Last_Sync"" rendezvous"); 
  52.  
  53.    end Pinger; 
  54.  
  55.    Tasks : array (Task_Range) of Pinger; 
  56.  
  57. begin 
  58.    for i in Tasks'Range loop 
  59.       Put_Line_w_Time_n_Task_Id (i, "is called at ""Hand_over_Id"""); 
  60.       Tasks (i).Hand_over_Id (i); 
  61.       Put_Line_w_Time_n_Task_Id (i, "released main task from ""Hand_over_Id"""); 
  62.    end loop; 
  63.  
  64.    for i in reverse Tasks'Range loop 
  65.       Put_Line_w_Time_n_Task_Id (i, "is called at ""Last_Sync"""); 
  66.       Tasks (i).Last_Sync; 
  67.       Put_Line_w_Time_n_Task_Id (i, "released main task from ""Last_Sync"""); 
  68.    end loop; 
  69. end Synchronize;