[erlang-questions] noob gen_leader question

db <>
Sun Apr 13 15:01:43 CEST 2008


Does worker instance of gen_leader spawn separate processes to perform a
task concurrently like in pool module?


On Mon, Apr 7, 2008 at 4:46 PM, Ulf Wiger (TN/EAB) <>
wrote:

> db skrev:
>
> > I have looked at gdict example.  Storing values into global dict goes to
> > the leader and lookup is done by workers on the local gen_leader instance.
> >
> > It seems gen_leader works by having worker pull task rather than master
> > push task.  Am I right?
> >
>
> No, the leader pushes the whole dictionary when elected, and
> then each update function, as all updates go through the
> leader process.
>
> So, for example (expanding the macro definition):
>
> -define(store(Dict,Expr,Legend),
>        gen_leader:leader_call(Dict, {store, fun(D) ->
>                                                     Expr
>                                             end})).
>
> -define(lookup(Dict, Expr, Legend),
>        gen_leader:call(Dict, {lookup, fun(D) ->
>                                               Expr
>                                       end})).
>
> %% dict functions that modify state:
> append(Key, Value, Dict) ->
>    gen_leader:leader_call(
>        Dict, {store, fun(D) ->
>                      dict:append(Key,Value,D)
>               end})).
>
> then, in the callback module:
>
> handle_leader_call({store,F}, _From, Dict, _E) ->
>    NewDict = F(Dict),
>    {reply, ok, {store, F}, NewDict};
>                  ^^^^ <- this is the push
>
>
> and here's where the workers receive it:
>
> from_leader({store,F}, Dict, _E) ->
>    NewDict = F(Dict),
>    {ok, NewDict}.
>
>
>
> BR,
> Ulf W
>


Thank you,
-- 
rk

That which we persist in doing becomes easier for us to do; not that the
nature of the thing itself is changed, but that our power to do is
increased.
-Ralph Waldo Emerson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080413/de5480c8/attachment.html>


More information about the erlang-questions mailing list