The following package defines an Ada semaphore abstraction:
generic
Initial : Natural:= 1; -- default initial value of semaphore
package Semaphore_Package is
type Semaphore is limited private;
procedure Wait (S : Semaphore);
procedure Signal (S : Semaphore);
private
type Semaphore is ...; ... not needed for this question
end Semaphore_Package;
Using the Semaphore_Package, show how the following communication paradigm (and its associated package specification) can be implemented.
A Multicast is where one task is able to send the same data to several waiting tasks. A package specification for the Multicast abstraction is given below:
package Multicast is
procedure Send (I ; Integer);
procedure Receive (I : out Integer\};
end Multicast;
The receiver tasks indicate their willingness to receive data by calling the procedure Receive defined in the package given above (in this example the data is of type Integer). The tasks are blocked by this call. A sender task indicates that it wishes to multicast data by calling the Send procedure. All tasks which are currently blocked on the receive are released when the sender invokes the Send procedure. The data passed by the sender is given to all waiting tasks. Once the Send procedure has finished, any new calls to Receive must wait for the next sender.
Show how the body of the Multicast package can be implemented using semaphores.