Advertisement
archidsky

THREE_TASKS - ADA

Apr 13th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.41 KB | None | 0 0
  1. with Ada.Text_Io; use Ada.Text_Io;
  2. procedure THREE_TASKS is
  3.     --Deklarasi Variael Global
  4.     COUNT, I, J : INTEGER range 0 .. INTEGER'LAST := 0;
  5.     --Spesifikasi tipe task
  6.     task INC is
  7.         entry UPDATE(C: in out INTEGER);
  8.     end INC;
  9.     task ONE;
  10.     task TWO;
  11.     --Bodi tipe task
  12.     --rendezvous task
  13.     task body INC is
  14.     begin
  15.         loop
  16.             accept UPDATE (C : in out INTEGER) do
  17.                 C := C+1;
  18.             end UPDATE;
  19.         end loop;
  20.     end INC;
  21.  
  22.     task body One is
  23.     begin
  24.         Ada.Text_IO.Put("Mulai TASK_ONE");
  25.         New_Line;
  26.         loop
  27.             I := I+1;
  28.             if I = 50 then exit; end if;
  29.             INC.UPDATE(COUNT);
  30.             Ada.Text_IO.Put("TASK_ONE :" & Integer'Image(I) & " COUNT =" & Integer'Image(COUNT));
  31.             New_Line;
  32.             delay 1.1;
  33.         end loop;
  34.     end ONE;
  35.  
  36.     task body TWO is
  37.     begin
  38.         Ada.Text_IO.Put("Mulai TASK_TWO");
  39.         New_Line;
  40.         loop
  41.             J := J+1;
  42.             if J = 50 then exit; end if;
  43.             INC.UPDATE(COUNT);
  44.             Ada.Text_IO.Put("TASK_TWO :" & Integer'Image(J) & " COUNT =" & Integer'Image(COUNT));
  45.             New_Line;
  46.             delay 0.7;
  47.         end loop;
  48.     end TWO;
  49.  
  50.     --program utama
  51.     begin -- THREE_TASKS
  52.  
  53.     -- TASK INC, ONE dan TWO semuanya akan memulai eksekusi segera
  54.     -- setelah kendali mencapai titik ini, bahkan sebelum sesuatu
  55.     -- statemen dalam program utama dieksekusi.
  56.     -- Ada standard tidak menetapkan urutan task mana yang mulai pertama.
  57.  
  58.     -- null
  59.         Ada.Text_IO.Put("Mulai contoh Rendezvous dalam Ada, Shared Variable Problem");
  60.         New_Line;
  61. end THREE_TASKS;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement