with Ada.Text_IO; procedure Test_Prot is -- FIFO on floating point numbers F1, F2, F3 : Float; -- just temporaries Size : constant := 100; -- buffer size type Indices is mod Size; -- modular type for indices type Pool_Type is array(Indices) of Float; protected Buffer is entry Read(C : out Float); -- mutually exclusive entries "protected" entry Write(C : in Float); private Pool : Pool_Type; -- the protected data items Count : Natural := 0; -- no type definitions in here In_Index, Out_Index : Indices := 0; end Buffer; protected body Buffer is entry Write(C : in Float) when Count < Pool'Length is -- guard holds up writer if buffer full begin Pool(In_Index) := C; In_Index := In_Index + 1; -- modular type wraps around to zero Count := Count + 1; end Write; entry Read(C : out Float) when Count > 0 is -- guard holds up reader if buffer empty begin C := Pool(Out_Index); Out_Index := Out_Index + 1; Count := Count - 1; end Read; end Buffer; begin Buffer.Write(1.5); -- these calls would normally be in tasks Buffer.Read(F1); -- here in main program, must avoid deadlock Buffer.Write(2.6); Buffer.Write(3.7); Buffer.Read(F2); Buffer.Read(F3); Ada.Text_io.Put_line("Write and Read gives " & Float'Image(F1) & " " & Float'Image(F2) & " " & Float'Image(F3)); for I in 1..250 loop Buffer.Write(Float(I)); -- loop through buffer several times Buffer.Read(F1); end loop; Buffer.Write(4.8); Buffer.Read(F1); Ada.Text_io.Put_line("Write and Read gives " & Float'Image(F1)); end Test_Prot;