Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Text_Io;
- use Text_Io;
- with Calendar;
- use Calendar;
- with Ada.Numerics.Elementary_Functions;
- use Ada.Numerics.Elementary_Functions;
- procedure Test is
- subtype Process_Id_Type is Positive range 1..4;
- task type Use_Processor (Process_Id : Process_Id_Type) is
- entry Halt;
- entry Start(Wait : Duration);
- entry Stop;
- end Use_Processor;
- task Screen_Manager is
- entry Get(Id : Process_Id_Type);
- entry Halt;
- end Screen_manager;
- task body Use_Processor is
- La_Grosse : Float := 144.0;
- La_Racine : Float := 12.0;
- Recycle : Time;
- wait : Duration;
- begin
- Main : loop
- loop
- select
- accept Start(Wait : Duration) do
- Use_processor.Wait := Wait;
- end Start;
- exit;
- or
- accept Halt;
- exit Main;
- end select;
- end loop;
- Recycle := Clock;
- loop
- delay until Recycle + Wait;
- Recycle := Recycle + Wait;
- select
- accept Stop;
- exit;
- or
- accept Halt;
- exit Main;
- else
- La_Grosse := La_Racine ** 2;
- La_Racine := Sqrt(La_Grosse);
- Screen_Manager.Get(Process_Id);
- end select;
- end loop;
- end loop main;
- end Use_Processor;
- task body Screen_Manager is
- Process_Id: Process_Id_Type;
- begin
- loop
- select
- accept Get(Id : Process_Id_Type) do
- Process_Id := Id;
- end Get;
- -- Text_Io.Put_line("Process_Id : " & Process_Id_type'Image(Process_Id));
- or
- accept Halt;
- exit;
- end select;
- end loop;
- end Screen_manager;
- Thread_1 : Use_processor(1);
- Thread_2 : Use_processor(2);
- Thread_3 : Use_processor(3);
- Thread_4 : Use_processor(4);
- begin
- Thread_1.Start(Wait => 0.0000025);
- Thread_2.Start(Wait => 0.0000025);
- Thread_3.Start(Wait => 0.0000025);
- Thread_4.Start(Wait => 0.025);
- delay 30.0;
- Thread_1.Halt;
- Thread_2.Halt;
- Thread_3.Halt;
- Thread_4.Halt;
- Screen_Manager.Halt;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement