Advertisement
Guest User

Untitled

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