Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.25 KB | None | 0 0
  1. with Ada.Text_IO;
  2. use Ada.Text_IO;
  3.  
  4. procedure Buf is
  5.    
  6.     Type TBuf is array(Integer range<>) of Character;
  7.    
  8.     protected Type Buf(Rozmiar:Integer) is
  9.         entry Wstaw(Ch: in Character);
  10.         entry Pobierz(Ch: out Character);
  11.         private
  12.         B : TBuf(1 .. Rozmiar);
  13.         LiczbElem := 0;
  14.         PozPob   : Integer:=1;
  15.         PozWstaw : Integer:=1;
  16.     end Buf;
  17.    
  18.     protected body Buf is
  19.         entry Wstaw(Ch in Character)
  20.         when LiczbElem < Rozmiar is begin
  21.             B(PozWstaw) := Ch;
  22.             LiczbElem := LiczbElem + 1;
  23.             if PozWstaw = B'Last then
  24.                 PozWstaw := 1;
  25.             else
  26.                 PozWstaw := PozWstaw + 1;
  27.             end if;
  28.         end Wstaw;
  29.        
  30.         entry Pobierz(Ch out Character)
  31.         when LiczbElem > 0 then
  32.             Ch := B(PozPob);
  33.             LiczbElem = LiczbaElem - 1;
  34.             if PozPob' = B'Last then
  35.                 PozPob := 1;
  36.             else
  37.                 PozPob := PozPob +1;
  38.             end if;
  39.        
  40.         end loop;
  41.        
  42.         end Pobierz;
  43.    
  44.     end Buf;
  45.        
  46.     Bufor : Buf(10);
  47.        
  48.        
  49.     task Producent;
  50.     Ch : Character := 'a';
  51.     task body Producent is begin
  52.         for I in 1..9 loop
  53.             Bufor.Wstaw(Ch);
  54.         end loop;
  55.     end Producent;
  56.    
  57.    
  58.     task Konsument;
  59.     Ch1 : Character;
  60.    
  61.     task body Konsument is begin
  62.         for I in 1..15 loop
  63.             Bufor.Pobierz(Ch1);
  64.             Put_Line(Ch1'Img);
  65.         end loop;
  66.     end Konsument;
  67.        
  68.          
  69.        
  70.        
  71.        
  72. begin
  73.    
  74.     null;
  75.        
  76. end Buf;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement