Advertisement
kator

ada producer consumer 1 element

Jun 6th, 2019
1,928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.13 KB | None | 0 0
  1. ------------------------------------------------------------------
  2. -- synchronous PC using Rendezvous --
  3. ------------------------------------------------------------------
  4. with Ada.Text_IO; use Ada.Text_IO;
  5.  
  6. procedure buff is
  7.     task Buf is
  8.         entry Put(x: in Integer);
  9.         entry Get(x: out Integer);
  10.     end Buf;
  11.  
  12.     task Producer;
  13.     task Consumer;
  14.  
  15.     task body Buf is
  16.         curr: Integer;
  17.     begin
  18.         loop
  19.             accept Put(x: in Integer) do
  20.                 curr := x;
  21.             end Put;
  22.             accept Get(x: out Integer) do
  23.                 x := curr;
  24.             end Get;
  25.         end loop;    
  26.     end Buf;
  27.  
  28.     task body Producer is
  29.     begin
  30.         for I in 1..14 loop
  31.             Buf.Put(I);
  32.         end loop;
  33.         Put_Line("Producer ending");
  34.     end Producer;
  35.  
  36.     task body Consumer is
  37.         x: Integer;
  38.     begin
  39.         loop
  40.             Buf.Get(x);
  41.             Put_Line("Get: " & Integer'Image(x));
  42.         end loop;
  43.         --Put_Line("Consumer ending");
  44.         --terminate;
  45.  
  46.     end Consumer;
  47.  
  48. begin
  49.     Put_Line("Hello world");
  50.    
  51.    --null;
  52. end buff;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement