fork download
  1. with Ada.Text_IO; use Ada.Text_IO;
  2. with Ada.Real_Time; use Ada.Real_Time;
  3.  
  4. procedure Main is
  5. task type Producer is
  6. entry Order (Char : in Character; Count : in Natural := 10; Delay_Time : in Duration := 0.0);
  7. entry Control (Stop : in Boolean);
  8. end Producer;
  9.  
  10. task body Producer is
  11. Stop_Task : Boolean := False;
  12. begin
  13. loop
  14. select
  15. -- Entrada para controle de término
  16. accept Control (Stop : in Boolean) do
  17. Stop_Task := Stop;
  18. end Control;
  19.  
  20. exit when Stop_Task;
  21.  
  22. or
  23. -- Entrada para receber ordens de impressão
  24. accept Order (Char : in Character; Count : in Natural := 10; Delay_Time : in Duration := 0.0) do
  25. for I in 1 .. Count loop
  26. Put(Char); -- Imprime o caractere na tela
  27. delay Delay_Time; -- Retardo entre as impressões
  28. end loop;
  29. New_Line;
  30. end Order;
  31. end select;
  32. end loop;
  33. end Producer;
  34.  
  35. -- Procedimento principal para o Process_Frame
  36. procedure Process_Frame is
  37. A, B : Producer; -- Instância das duas tarefas
  38. begin
  39. -- Tarefa A imprime 'A' 10 vezes sem delay
  40. A.Order('A', 10);
  41.  
  42. -- Tarefa B imprime 'B' 10 vezes com delay de 1.0 segundo
  43. B.Order('B', 10, 1.0);
  44.  
  45. -- Tarefa A imprime 'A' 100 vezes sem delay
  46. A.Order('A', 100);
  47.  
  48. -- Tarefa B termina
  49. B.Control(True);
  50.  
  51. -- Tarefa A termina
  52. A.Control(True);
  53. end Process_Frame;
  54.  
  55. begin
  56. -- Chamada do procedimento principal
  57. Process_Frame;
  58. end Main;
  59.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
AAAAAAAAAA
BBBBBBBBBB
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA