comp.lang.ada
 help / color / mirror / Atom feed
From: stt@dsd.camb.inmet.com (Tucker Taft)
Subject: Re: Broadcast facility
Date: Wed, 26 Oct 1994 01:23:39 GMT
Date: 1994-10-26T01:23:39+00:00	[thread overview]
Message-ID: <Cy9AJF.Dxy@inmet.camb.inmet.com> (raw)
In-Reply-To: 1994Oct25.121138.22277@sei.cmu.edu

In article <1994Oct25.121138.22277@sei.cmu.edu>,
Philip Brashear <brashear@ajpo.sei.cmu.edu> wrote:

>As Technical Editor of Ada Letters, I received the following message.
>Does anyone have a response?  E-mail may be sent to me and I will forward
>it to the questioner.
>
>Philip: I remember that Ada Letters used to have a "Dear Ada" section,
>which discussed issues on language definition and on how to use Ada to
>solve some problems. But I have not found this section in recent issues.
>Below is a question I have. Please forward it to the appropriate person,
>Thanks.
>
>--------  --- ------ ----- --- -- -------- - --------- ------- -- ---
>Question: Has anyone shown how to simulate a broadcast command in Ada?
>--------  --- ------ ----- --- -- -------- - --------- ------- -- ---

[I will e-mail this response as well.]
A little more context would help know exactly what is meant
by a "broadcast command."  But if we presume the goal is for
a number of tasks to receive the same message, then it is quite
straightforward, using either an accept statement in a loop,
or, in Ada 9X, a protected type whose entry barrier remains
true until the last waiting task receives the message.

This presumes you want to send the message to all tasks that
are waiting on a given entry.  Perhaps more likely is that
you have a more asynchronous communication approach, and each
task has a mailbox or equivalent.  In that case, you just pass
in a list or array of references to mailboxes, and send the message
to each one.

Here are examples of each approach:

   protected Broadcast is
       procedure Broadcast_Message(Message : Message_Type);
       entry Wait_For_Message(Message : out Message_Type);
   private
       Message_To_Be_Broadcast : Message_Type;
       Message_Present : Boolean := False;
   end Broadcast;

   protected body Broadcast is
       procedure Broadcast_Message(Message : Message_Type) is
       begin
           Message_To_Be_Broadcast := Message;
           Message_Present := True;
       end Broadcast_Message;

       entry Wait_For_Message(Message : out Message_Type) 
         when Message_Present is
       begin
           Message := Message_To_Be_Broadcast;
           if Wait_For_Message'Count = 0 then
               -- Last one out closes the door
               Message_Present := False;
           end if;
       end Wait_For_Message;
   end Broadcast;

Something similar could be done using accept statements.

Here is a more asynchronous approach using mailboxes and address lists:

   protected type Mailbox is
       procedure Put(Msg : Message_Type);
       entry Get(Msg : out Message_Type);
   private
       List : Message_List;
   end Mailbox;

   protected body Mailbox is
       procedure Put(Msg : Message_Type) is
       begin
           Add_To_Message_List(List, Msg);
       end Put;

       entry Get(Msg : out Message_Type) when not Is_Empty(List) is
       begin
           Remove_From_List(List, Msg);
       end Get;
   end Mailbox;

   type Address is access all Mailbox;
   type Address_List is array(Positive range <>) of Address;
   procedure Broadcast(Msg : Message_Type; Mailing_List : Address_List) is
   begin
       for I in Mailing_List'Range loop
            Mailing_List(I).Put(Msg);
       end loop;
   end Broadcast;

In general, any kind of software broadcast requires a loop,
either implicit (1st example) or explicit (2nd example).  
Of course if you have hardware broadcast on your LAN, 
then an interface can be written to allow that to be used.
As mentioned above, much depends on exactly what is meant 
by a "broadcast command."

>Thanks!
>Phil Brashear

-Tucker Taft   stt@inmet.com
Intermetrics, Inc.
Cambridge, MA  02138



  parent reply	other threads:[~1994-10-26  1:23 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1994-10-25 16:11 Broadcast facility Philip Brashear
1994-10-26  1:04 ` Dale Stanbrough
1994-10-26  1:23 ` Tucker Taft [this message]
1994-10-26 11:10   ` R. William Beckwith
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox