Advertisement
Guest User

Untitled

a guest
Apr 30th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.39 KB | None | 0 0
  1.  
  2. with Ada.Text_IO; use Ada.Text_IO;
  3.  
  4. package body paczka is
  5.  
  6.    procedure p is
  7.    
  8.       task Bufor is
  9.          entry Wstaw(x: in Integer);
  10.          entry Pobierz(x: out Integer);
  11.       end Bufor;
  12.  
  13.       task body Bufor is
  14.          Buf: array(0..19) of Integer;
  15.          We, Wy: Integer := 0;
  16.          Licznik: Integer := 0;
  17.       begin
  18.          loop
  19.             select
  20.                when Licznik < 20 =>
  21.                   accept Wstaw(X: in Integer) do
  22.                      Buf(We) := X;
  23.                   end Wstaw;
  24.                   Licznik := Licznik + 1;
  25.                   We := (We + 1) mod 20;
  26.             or
  27.                when Licznik > 0 =>
  28.                   accept Pobierz(X: out Integer) do
  29.                      X := Buf(Wy);
  30.                   end Pobierz;
  31.                   Licznik := Licznik - 1;
  32.                   Wy := (Wy + 1) mod 20;
  33.             end select;
  34.          end loop;
  35.       end Bufor;
  36.    
  37.    
  38.    
  39.       task Producent;
  40.    
  41.       task body Producent is
  42.          Elem: Integer := 5;
  43.       begin
  44.          loop
  45.             Elem := Elem + 1;
  46.             B.Bufor.Wstaw(Elem);
  47.          
  48.          end loop;
  49.       end Producent;
  50.    
  51.    
  52.    
  53.    
  54.       task Konsument;
  55.    
  56.       task body Konsument is
  57.          Elem: Integer;
  58.       begin
  59.          loop
  60.  
  61.             Bufor.Pobierz(Elem);
  62.             Put_Line (Elem);
  63.  
  64.          end loop;
  65.       end Konsument;
  66.    
  67.    begin
  68.       null;
  69.    end p;
  70.  
  71.    
  72.  
  73. end paczka;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement