Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Ada.Text_IO, Ada.Characters.Handling;
- procedure bead is
- type Color_Type is (Red, RedYellow, Green, Yellow);
- task type Signal;
- protected Lamp is
- procedure Switch;
- function Color return Color_Type;
- private
- Agent : access Signal;
- Actual_Color : Color_Type := Red;
- end Lamp;
- protected body Lamp is
- function Color return Color_Type is
- begin
- return Actual_Color;
- end Color;
- procedure Switch is
- begin
- Agent := new Signal;
- if Actual_Color = Yellow then
- Actual_Color := Red;
- else
- Actual_Color := Color_Type'Val(Color_Type'Pos(Actual_Color) + 1);
- end if;
- end Switch;
- end Lamp;
- task Controller is
- entry Stop;
- end Controller;
- task body Controller is
- begin
- loop
- select
- accept Stop;
- exit;
- else
- delay 3.0;
- Lamp.Switch;
- delay 1.0;
- Lamp.Switch;
- delay 3.0;
- Lamp.Switch;
- delay 2.0;
- Lamp.Switch;
- end select;
- end loop;
- end Controller;
- protected Crossroad is
- entry Cross(Time_To_Cross : Duration);
- procedure Wake_Up;
- end Crossroad;
- task body Signal is
- begin
- Crossroad.Wake_Up;
- end Signal;
- type String_Access is access String;
- task type Vehicle(Plate: String_Access);
- task body Vehicle is
- Crossed : Boolean := False;
- Time_To_Cross : Duration := 1.0;
- begin
- Ada.Text_IO.Put_Line(Plate.all & " a lampahoz erkezett.");
- while not Crossed loop
- select
- Crossroad.Cross(Time_To_Cross);
- Crossed := True;
- else
- if Time_To_Cross = 1.0 then
- Time_To_Cross := 3.0;
- end if;
- end select;
- end loop;
- Ada.Text_IO.Put_Line(Plate.all & " athaladt.");
- end Vehicle;
- protected body Crossroad is
- entry Cross(Time_To_Cross : Duration) when Lamp.Color = Green is
- begin
- delay Time_To_Cross;
- end Cross;
- procedure Wake_Up is
- begin
- null;
- end Wake_Up;
- end Crossroad;
- Car : access Vehicle;
- begin
- for i in 1..10 loop
- Car := new Vehicle(new String'("Auto" & Integer'Image(i)));
- delay 1.0;
- end loop;
- Ada.Text_IO.Skip_Line;
- Controller.Stop;
- Ada.Text_IO.Put_Line("A vezerlo leallt.");
- end bead;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement