-1

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;
Mike
  • 47,263
  • 29
  • 113
  • 177
Dardan
  • 43
  • 4
  • Any help to make this work please – Dardan Jun 03 '12 at 14:48
  • Question is how to adapt this code that a Task it is going to call enrty Waiting that this Task it it not going to be on waiting state if (if Selecting_Marker /= Marker then ) except before its initialisations? – Dardan Jun 03 '12 at 15:02

1 Answers1

2

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:

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
Shark8
  • 4,095
  • 1
  • 17
  • 31