comp.lang.ada
 help / color / mirror / Atom feed
* Broadcast facility
@ 1994-10-25 16:11 Philip Brashear
  1994-10-26  1:04 ` Dale Stanbrough
  1994-10-26  1:23 ` Tucker Taft
  0 siblings, 2 replies; 4+ messages in thread
From: Philip Brashear @ 1994-10-25 16:11 UTC (permalink / raw)


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?
--------  --- ------ ----- --- -- -------- - --------- ------- -- ---


Thanks!
Phil Brashear




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Broadcast facility
  1994-10-25 16:11 Broadcast facility Philip Brashear
@ 1994-10-26  1:04 ` Dale Stanbrough
  1994-10-26  1:23 ` Tucker Taft
  1 sibling, 0 replies; 4+ messages in thread
From: Dale Stanbrough @ 1994-10-26  1:04 UTC (permalink / raw)


In article <1994Oct25.121138.22277@sei.cmu.edu> Philip Brashear,
brashear@ajpo.sei.cmu.edu writes:
>--------  --- ------ ----- --- -- -------- - --------- ------- -- ---
>Question: Has anyone shown how to simulate a broadcast command in Ada?
>--------  --- ------ ----- --- -- -------- - --------- ------- -- ---

Yes, it's called the Mandate. :-)

Dale



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Broadcast facility
  1994-10-25 16:11 Broadcast facility Philip Brashear
  1994-10-26  1:04 ` Dale Stanbrough
@ 1994-10-26  1:23 ` Tucker Taft
  1994-10-26 11:10   ` R. William Beckwith
  1 sibling, 1 reply; 4+ messages in thread
From: Tucker Taft @ 1994-10-26  1:23 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Broadcast facility
  1994-10-26  1:23 ` Tucker Taft
@ 1994-10-26 11:10   ` R. William Beckwith
  0 siblings, 0 replies; 4+ messages in thread
From: R. William Beckwith @ 1994-10-26 11:10 UTC (permalink / raw)


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

>--------  --- ------ ----- --- -- -------- - --------- ------- -- ---
>Question: Has anyone shown how to simulate a broadcast command in Ada?
>--------  --- ------ ----- --- -- -------- - --------- ------- -- ---

If you asking about broadcast in the Smalltalk sense, it is easy in
Ada 9X.

i.e. each object has a list of dependents.  If the state of an object
is changed it sends its list of dependents an update message.  In
Smalltalk this capability is inherited from the root Object class.

It is interesting to note that this mechanism wreaks havoc on
garbage collectors and reference counting schemes.  If Object D
is a dependant of Object P, then you don't want Object P's reference
to Object D to cause Object D to continue to exist.  ParcPlace's
product has `weak' reference which is ignored by the garbage
collector for just this purpose.

We have had to create a similiar weak reference to support
Fresco's broadcast mechanism in a reference counting
environment.

... Bill

-- 
e-mail: Bill.Beckwith@ois.com       |    Team Ada
Objective Interface Systems, Inc.   | dist, full O-O
1895 Preston White Drive, Suite 250 | multithreading
Reston, VA  22091-5448  U.S.A.      |    built in



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1994-10-26 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1994-10-25 16:11 Broadcast facility Philip Brashear
1994-10-26  1:04 ` Dale Stanbrough
1994-10-26  1:23 ` Tucker Taft
1994-10-26 11:10   ` R. William Beckwith

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