Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Ada.Text_IO;
- use Ada.Text_IO;
- procedure Buf is
- Type TBuf is array(Integer range<>) of Character;
- protected Type Buf(Rozmiar:Integer) is
- entry Wstaw(Ch: in Character);
- entry Pobierz(Ch: out Character);
- private
- B : TBuf(1 .. Rozmiar);
- LiczbElem := 0;
- PozPob : Integer:=1;
- PozWstaw : Integer:=1;
- end Buf;
- protected body Buf is
- entry Wstaw(Ch in Character)
- when LiczbElem < Rozmiar is begin
- B(PozWstaw) := Ch;
- LiczbElem := LiczbElem + 1;
- if PozWstaw = B'Last then
- PozWstaw := 1;
- else
- PozWstaw := PozWstaw + 1;
- end if;
- end Wstaw;
- entry Pobierz(Ch out Character)
- when LiczbElem > 0 then
- Ch := B(PozPob);
- LiczbElem = LiczbaElem - 1;
- if PozPob' = B'Last then
- PozPob := 1;
- else
- PozPob := PozPob +1;
- end if;
- end loop;
- end Pobierz;
- end Buf;
- Bufor : Buf(10);
- task Producent;
- Ch : Character := 'a';
- task body Producent is begin
- for I in 1..9 loop
- Bufor.Wstaw(Ch);
- end loop;
- end Producent;
- task Konsument;
- Ch1 : Character;
- task body Konsument is begin
- for I in 1..15 loop
- Bufor.Pobierz(Ch1);
- Put_Line(Ch1'Img);
- end loop;
- end Konsument;
- begin
- null;
- end Buf;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement