Advertisement
Guest User

tmp

a guest
Apr 7th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 2.26 KB | None | 0 0
  1. with Text_Io;
  2. use Text_Io;
  3. with Calendar;
  4. use Calendar;
  5. with Ada.Numerics.Elementary_Functions;
  6. use Ada.Numerics.Elementary_Functions;
  7.  
  8. procedure Test is
  9.  
  10.    subtype Process_Id_Type is Positive range 1..4;
  11.  
  12.    task type Use_Processor (Process_Id : Process_Id_Type) is
  13.       entry Halt;
  14.       entry Start(Wait : Duration);
  15.       entry Stop;
  16.    end Use_Processor;
  17.    task Screen_Manager is
  18.       entry Get(Id : Process_Id_Type);
  19.       entry Halt;
  20.    end Screen_manager;
  21.  
  22.    task body Use_Processor is
  23.       La_Grosse : Float := 144.0;
  24.       La_Racine : Float := 12.0;
  25.       Recycle : Time;
  26.       wait : Duration;
  27.    begin
  28.   Main : loop
  29.          loop
  30.             select
  31.                accept Start(Wait : Duration) do
  32.                   Use_processor.Wait := Wait;
  33.                end Start;
  34.                exit;
  35.             or
  36.                accept Halt;
  37.                exit Main;
  38.             end select;
  39.          end loop;
  40.          Recycle := Clock;
  41.          loop
  42.             delay until Recycle + Wait;
  43.             Recycle := Recycle + Wait;
  44.             select
  45.                accept Stop;
  46.                exit;
  47.             or
  48.                accept Halt;
  49.                exit Main;
  50.             else
  51.                La_Grosse := La_Racine ** 2;
  52.                La_Racine := Sqrt(La_Grosse);
  53.                Screen_Manager.Get(Process_Id);
  54.             end select;
  55.          end loop;
  56.       end loop main;
  57.    end Use_Processor;
  58.    task body Screen_Manager is
  59.       Process_Id: Process_Id_Type;
  60.    begin
  61.       loop
  62.          select
  63.             accept Get(Id : Process_Id_Type) do
  64.                Process_Id := Id;
  65.             end Get;
  66. --            Text_Io.Put_line("Process_Id : " & Process_Id_type'Image(Process_Id));
  67.          or
  68.             accept Halt;
  69.             exit;
  70.          end select;
  71.       end loop;
  72.    end Screen_manager;
  73.  
  74.    Thread_1 : Use_processor(1);
  75.    Thread_2 : Use_processor(2);
  76.    Thread_3 : Use_processor(3);
  77.    Thread_4 : Use_processor(4);
  78.  
  79. begin
  80.    Thread_1.Start(Wait => 0.0000025);
  81.    Thread_2.Start(Wait => 0.0000025);
  82.    Thread_3.Start(Wait => 0.0000025);
  83.    Thread_4.Start(Wait => 0.025);
  84.  
  85.    delay 30.0;
  86.    Thread_1.Halt;
  87.    Thread_2.Halt;
  88.    Thread_3.Halt;
  89.    Thread_4.Halt;
  90.    Screen_Manager.Halt;
  91. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement