From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1087b2696d1f5370 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-10-25 23:36:31 PST Newsgroups: comp.lang.ada Path: nntp.gmd.de!xlink.net!howland.reston.ans.net!noc.near.net!inmet!dsd!stt From: stt@dsd.camb.inmet.com (Tucker Taft) Subject: Re: Broadcast facility Message-ID: Sender: news@inmet.camb.inmet.com Organization: Intermetrics, Inc. References: <1994Oct25.121138.22277@sei.cmu.edu> Date: Wed, 26 Oct 1994 01:23:39 GMT Date: 1994-10-26T01:23:39+00:00 List-Id: In article <1994Oct25.121138.22277@sei.cmu.edu>, Philip Brashear 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