Consider the following controller (protected object) in Ada95 to adapt that a Task calls Waiting()
this one its not going to be put on waiting if the waiting marker (Marker) corresponds already on the marker of selection (Selecting_Marker
) only naturally before it's initialization:
protected type Controller is
entry Waiting(Marker : in Marker_Type);
procedure WakeUp(Marker : in Marker_Type);
private
Tentative_Count : Natural := 0;
Selecting_Marker : Marker_Type;
end Controller;
protected body Controller is
entry Waiting (Marker : in Marker_Type) when Tentative_Count > 0 is
begin
Tentative_Count := Tentative_Count - 1;
if Selecting_Marker /= Marker then
requeue Waiting;
end if;
end Waiting;
procedure WakeUp (Marker : in Marker_Type) is
begin
Selecting_Marker := Marker;
Tentative_Count := Waiting'Count;
end WakeUp;
end Controller;