with Ada.Text_IO; use Ada.Text_IO;
with Ada.Real_Time; use Ada.Real_Time;
procedure Main is
task type Producer is
entry Order (Char : in Character; Count : in Natural := 10; Delay_Time : in Duration := 0.0);
entry Control (Stop : in Boolean);
end Producer;
task body Producer is
Stop_Task : Boolean := False;
begin
loop
select
-- Entrada para controle de término
accept Control (Stop : in Boolean) do
Stop_Task := Stop;
end Control;
exit when Stop_Task;
or
-- Entrada para receber ordens de impressão
accept Order (Char : in Character; Count : in Natural := 10; Delay_Time : in Duration := 0.0) do
for I in 1 .. Count loop
Put(Char); -- Imprime o caractere na tela
delay Delay_Time; -- Retardo entre as impressões
end loop;
New_Line;
end Order;
end select;
end loop;
end Producer;
-- Procedimento principal para o Process_Frame
procedure Process_Frame is
A, B : Producer; -- Instância das duas tarefas
begin
-- Tarefa A imprime 'A' 10 vezes sem delay
A.Order('A', 10);
-- Tarefa B imprime 'B' 10 vezes com delay de 1.0 segundo
B.Order('B', 10, 1.0);
-- Tarefa A imprime 'A' 100 vezes sem delay
A.Order('A', 100);
-- Tarefa B termina
B.Control(True);
-- Tarefa A termina
A.Control(True);
end Process_Frame;
begin
-- Chamada do procedimento principal
Process_Frame;
end Main;
d2l0aCBBZGEuVGV4dF9JTzsgdXNlIEFkYS5UZXh0X0lPOwp3aXRoIEFkYS5SZWFsX1RpbWU7IHVzZSBBZGEuUmVhbF9UaW1lOwoKcHJvY2VkdXJlIE1haW4gaXMKICAgdGFzayB0eXBlIFByb2R1Y2VyIGlzCiAgICAgIGVudHJ5IE9yZGVyIChDaGFyIDogaW4gQ2hhcmFjdGVyOyBDb3VudCA6IGluIE5hdHVyYWwgOj0gMTA7IERlbGF5X1RpbWUgOiBpbiBEdXJhdGlvbiA6PSAwLjApOwogICAgICBlbnRyeSBDb250cm9sIChTdG9wIDogaW4gQm9vbGVhbik7CiAgIGVuZCBQcm9kdWNlcjsKCiAgIHRhc2sgYm9keSBQcm9kdWNlciBpcwogICAgICBTdG9wX1Rhc2sgOiBCb29sZWFuIDo9IEZhbHNlOwogICBiZWdpbgogICAgICBsb29wCiAgICAgICAgIHNlbGVjdAogICAgICAgICAgICAtLSBFbnRyYWRhIHBhcmEgY29udHJvbGUgZGUgdMOpcm1pbm8KICAgICAgICAgICAgYWNjZXB0IENvbnRyb2wgKFN0b3AgOiBpbiBCb29sZWFuKSBkbwogICAgICAgICAgICAgICBTdG9wX1Rhc2sgOj0gU3RvcDsKICAgICAgICAgICAgZW5kIENvbnRyb2w7CgogICAgICAgICAgICBleGl0IHdoZW4gU3RvcF9UYXNrOwoKICAgICAgICAgb3IKICAgICAgICAgICAgLS0gRW50cmFkYSBwYXJhIHJlY2ViZXIgb3JkZW5zIGRlIGltcHJlc3PDo28KICAgICAgICAgICAgYWNjZXB0IE9yZGVyIChDaGFyIDogaW4gQ2hhcmFjdGVyOyBDb3VudCA6IGluIE5hdHVyYWwgOj0gMTA7IERlbGF5X1RpbWUgOiBpbiBEdXJhdGlvbiA6PSAwLjApIGRvCiAgICAgICAgICAgICAgIGZvciBJIGluIDEgLi4gQ291bnQgbG9vcAogICAgICAgICAgICAgICAgICBQdXQoQ2hhcik7IC0tIEltcHJpbWUgbyBjYXJhY3RlcmUgbmEgdGVsYQogICAgICAgICAgICAgICAgICBkZWxheSBEZWxheV9UaW1lOyAtLSBSZXRhcmRvIGVudHJlIGFzIGltcHJlc3PDtWVzCiAgICAgICAgICAgICAgIGVuZCBsb29wOwogICAgICAgICAgICAgICBOZXdfTGluZTsKICAgICAgICAgICAgZW5kIE9yZGVyOwogICAgICAgICBlbmQgc2VsZWN0OwogICAgICBlbmQgbG9vcDsKICAgZW5kIFByb2R1Y2VyOwoKICAgLS0gUHJvY2VkaW1lbnRvIHByaW5jaXBhbCBwYXJhIG8gUHJvY2Vzc19GcmFtZQogICBwcm9jZWR1cmUgUHJvY2Vzc19GcmFtZSBpcwogICAgICBBLCBCIDogUHJvZHVjZXI7IC0tIEluc3TDom5jaWEgZGFzIGR1YXMgdGFyZWZhcwogICBiZWdpb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