[erlang-questions] Sending a message to all linked processes

John Haugeland stonecypher@REDACTED
Thu May 29 21:35:00 CEST 2008


> I was wondering if there is a simple and straightforward way to send a
> message to all linked processes. Now, I am aware that a process exit signal
> is transmitted in a functionally similar manner, so it seems that at least
> some form of "broadcast to all linked processes" operation exists within the
> runtime. But is it possible to invoke such functionality directly from
> source code?
>

There may be a better way, but here's how I do it:

get_linked_processes() -> [U] = [V||{links,V}<-process_info(self())], U.

[ LP ! message || LP <- get_linked_processes() ].

I suspect that process_info() isn't particularly cheap, so I recommend
reconsidering the bookkeeping.

  - John

---
GuaranteedVPS.com - bandwidth commitments and root starting from $12.98/mo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080529/fc00fe36/attachment.htm>


More information about the erlang-questions mailing list