Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. -bufor wieloelementowy na typie chronionym producent-konsument
  2.  
  3. with Ada.Text_IO, Ada.Numerics.Float_Random, buforW;
  4. use Ada.Text_IO, Ada.Numerics.Float_Random;
  5.  
  6. procedure buforpk is
  7.  
  8. package packageBuf is new buforw(10,Float);
  9.  
  10.  
  11. --producent
  12. task type Producent is
  13. entry Start;
  14. entry Stop;
  15. end Producent;
  16.  
  17. task body Producent is
  18. G: Generator;
  19. Tmp: Float;
  20. begin
  21. accept Start;
  22. loop
  23. select
  24. accept Stop;
  25. Put_Line("Producent out");
  26. exit;
  27. else
  28. Reset(G);
  29. Tmp := Random(G);
  30. Put_Line("P: wstawiam: " & Tmp'Img);
  31. packageBuf.BufW.Wstaw(Tmp);
  32. Put_Line("P: wstawione");
  33. delay 1.0;
  34. end select;
  35. end loop;
  36. end Producent;
  37.  
  38. --konsument
  39. task type Konsument is
  40. entry Start;
  41. entry Stop;
  42. end Konsument;
  43.  
  44. task body Konsument is
  45. Tmp: Float;
  46. begin
  47. accept Start;
  48. loop
  49. select
  50. accept Stop;
  51. Put_Line("Konsument out");
  52. exit;
  53. else
  54. packageBuf.BufW.Pobierz(Tmp);
  55. Put_Line("K: pobrano: " & Tmp'Img);
  56. end select;
  57. end loop;
  58. end Konsument;
  59.  
  60.  
  61. --main
  62. Producent1: Producent;
  63. Konsument1: Konsument;
  64. begin
  65. Producent1.Start;
  66. delay 3.0;
  67. Konsument1.Start;
  68. delay 5.0;
  69. Producent1.Stop;
  70. Konsument1.Stop;
  71.  
  72.  
  73. end buforpk;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement