[erlang-questions] Calling multiple processes simultaneously

Edmond Begumisa ebegumisa@REDACTED
Tue May 24 00:30:56 CEST 2011


OH,

I of course assumed the gen_server call was heavy enough to warrant a new  
process for each call otherwise you wouldn't have needed to abandon your  
existing loop looking for a way to call them all simultaneously.

- Edmond -

On Tue, 24 May 2011 06:54:23 +1000, Edmond Begumisa  
<ebegumisa@REDACTED> wrote:

> Actually,
>
>   {reply, ok, _} = gen_server:call(foo, bar),
>
> ...should be ...
>
>   _ = gen_server:call(foo, bar),
>
> ... since you don't care about the reply, but just want a reply.
>
> - Edmond -
>
> On Tue, 24 May 2011 06:50:54 +1000, Edmond Begumisa  
> <ebegumisa@REDACTED> wrote:
>
>> Another option...
>>
>> call_gen_servers(Pids) ->
>>      Ref = erlang:make_ref(),
>>      Caller = self(),
>>      lists:foreach(fun(P) ->
>>                      spawn_link(fun() ->
>>                                      {reply, ok, _} =  
>> gen_server:call(foo, bar),
>>                                      Caller ! {self(), Ref}
>>                                 end).
>>                    end, Pids),
>>      ok = wait_gen_servers(length(Pids), Ref).
>>
>> wait_gen_servers(0, _) ->
>>      ok;
>> wait_gen_servers(N, Ref) ->
>>      receive
>>          {_, Ref} ->
>>              wait_gen_servers(N-1, Ref)
>>      end.
>>
>> You could also add the timeout.
>>
>> - Edmond -
>>
>> On Tue, 24 May 2011 02:01:23 +1000, Martin Dimitrov  
>> <mrtndimitrov@REDACTED> wrote:
>>
>>> Hi, please, advise on this one,
>>>
>>> We have several hundred processes (gen_servers) . At one point the
>>> program has to send them a message that needs to be handled before the
>>> calling process can continue executing. This naturally led us to use
>>> gen_server:call in loop over the processes.
>>>
>>> I started to wonder if there is a more efficient way of doing it since
>>> the calling process doesn’t care about the return value – just needs to
>>> be sure that all processes had handled the message. Can we somehow call
>>> the processes simultaneously? Something similar to  
>>> gen_server:multi_call
>>> but for one node with different processes?
>>>
>>> Regards,
>>>
>>> Martin
>>>
>>> _______________________________________________
>>> erlang-questions mailing list
>>> erlang-questions@REDACTED
>>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
>


-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the erlang-questions mailing list