Domanda

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;
È stato utile?

Soluzione

The object is to alter the behavior of the protected object, likely the following line:

entry Waiting (Marker : in Marker_Type) when Tentative_Count > 0 is

I'm not well-versed in protected objects, so won't offer any more than that except to say you'd probably be better off a) rereading the book's chapter on protected objects; and b) understanding what the objective of the code is and what the teacher/book is asking.

Part b is especially important, as in real life you need to be able to translate specifications into an implementation; and oftentimes the exact-wording is at odds with the examples and/or the example/reasoning.

Additional resources:

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top