Consider the following package specification which provides a procedure to search part of a large character array for a unique fixed-length string. The procedure returns the position of the start of the string if it is found.
package Search_Support is
type Array_Bounds is range 1 .. 1_000_000_000;
type Large_Array is array (Array_Bounds) of Character;
type Pointer is access Large_Array;
procedure Search(Pt: Pointer;
Lower, Upper: Array_Bounds;
Looking_For : Search_String;
Found : out Boolean;
At_Location : out Array_Bounds) ;
end Search_Support;
Three tasks wish to perform a concurrent search of the array for the same string; they are derived from a common task type.
task type Searcher(Search_Array: Pointer;
Lower, Upper: Array_Bounds) is
entry Find(Looking_For : Search_String) ;
entry Get_Result (At_Location : out Array_Bounds) ;
end Searcher;
The string to be found is passed via an initial rendezvous with the tasks. Sketch the body of the task type (and any other objects you might need) so that when one task finds the string, all other tasks are immediately informed of the string's location so that further fruitless search is avoided. Assume that the SearchString will be found by one of the three tasks. Furthermore, all tasks must be prepared to pass back the result via the Get Result entry.