with Text_IO; use TEXT_IO; --with Ada.Integer_Text_IO; use Ada.Integer_TEXT_IO; Procedure SISTEMA is MAX_NUM: constant := 11; MEKL_COUNT: constant := 3; STEP: constant := 0; STEP2: constant := 2; TIME: constant DURATION := 10.0; SMALLTIME: constant DURATION := 0.1; ENDTIME: constant DURATION := 1.0; task Generators is entry start; entry stop; end Generators; task type Mekletajs is entry init (ParamName:STRING; index:INTEGER); -- STRING entry print_score; entry stop; end Mekletajs; task type Resurss is entry raise_count; entry request_token (Result: out BOOLEAN); entry stop; end Resurss; R: array(1..MAX_NUM) of Resurss; M: array(1..MEKL_COUNT) of Mekletajs; S: STRING(1..10); task body Generators is J: INTEGER; T: BOOLEAN; begin accept start; T := true; J := 1; while T loop R(J).raise_count; J := (J + STEP) mod MAX_NUM; J := J + 1; delay(SMALLTIME); select accept stop do T := False; end Stop; else null; end select; end loop ; end Generators; task body Mekletajs is myName: STRING(1..10); score: INTEGER; My_Index: INTEGER; token: BOOLEAN; InLoop: BOOLEAN; InProcess: BOOLEAN; begin Token := True; select accept init(ParamName: in STRING; index: in INTEGER) do myName := ParamName; score := 0; my_index := (index * index) mod MAX_NUM + 1; end init; end select; InProcess := True; while InProcess loop InLoop := True; for J in 1 .. MAX_NUM loop if InLoop then my_index := (my_index - STEP2) mod MAX_NUM + 1; R(my_index).request_token(token); if token then begin score := score + 1; Put_Line (MyName & " dabuju : " & integer'image(My_Index)); InLoop := False; end; end if; delay(SMALLTIME); end if; end loop; select accept print_score do put_Line (myName & " : " & Integer'Image(Score)); InProcess := False; end print_score; else null; end select; end loop; accept Stop; end Mekletajs; task body Resurss is count: INTEGER; Result: BOOLEAN := False; InLoop: BOOLEAN; begin InLoop := True; Count := 0; while InLoop loop select accept raise_count do count := count + 1; end raise_count ; or accept request_token(Result: out BOOLEAN) do if count > 0 then Result := True; count := count -1; else Result := False; end if; end request_token; or accept stop do InLoop := False; end stop; end select; end loop; end Resurss; begin for I in 1 .. MEKL_COUNT loop if I = 1 then S := "Pirmais "; end if; if I = 2 then S := "Otrais "; end if; if I = 3 then S := "Tresais "; end if; M(I).init(S,I); end loop; Generators.start; delay(TIME); Generators.stop; delay(ENDTIME); for I in 1 .. MEKL_COUNT loop M(I).print_score; M(I).stop; end loop; for I in 1 .. MAX_NUM loop R(I).stop; end loop; end SISTEMA;