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

John Haugeland stonecypher@REDACTED
Fri May 30 16:20:54 CEST 2008


I suppose I could.  However, since I use get_linked_processes() for other
things too, I made a library function out of it several months ago.  When I
answered the question, I just cut and pasted the library function.

When giving code examples, the easier they are to read, the better.  I don't
doubt that the receiving reader could have made that substitution
themselves.



On Fri, May 30, 2008 at 6:47 AM, Hynek Vychodil <vychodil.hynek@REDACTED>
wrote:

> you can just write :
>
> [ LP ! Msg || LP <- begin {links, P} = process_info(self(), links), P end
> ].
>
> or without pattern match check (less reliable way):
>
> [ LP ! Msg || LP <- element(2, process_info(self(), links)) ].
>
> 2008/5/29 John Haugeland <stonecypher@REDACTED>:
>
>>
>> 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
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
>>
>
>
>
> --
> --Hynek (Pichi) Vychodil




-- 
---
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/20080530/1e06d3f5/attachment.htm>


More information about the erlang-questions mailing list