Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to start multiple instances of the same module/function under the Supervisor behavior in erlang?
    primarykey
    data
    text
    <p>Having a module/function <strong>mymodule</strong> , how to start it multiple times under the <a href="http://www.erlang.org/doc/man/supervisor.html#type-child_spec" rel="nofollow">supervisor</a> behavior ? </p> <p>I need for example 2 instances of the <strong>same process</strong> (mymodule) to be started concurrently. I called the children identifiers as <strong>child1</strong> and <strong>child2</strong>. They both point to the <strong>mymodule</strong> module that I want to start. I have specified two different functions to to start each instance of the worker process "mymodule" ( start_link1 and start_link2 )</p> <pre><code>-module(my_supervisor). -behaviour(supervisor). -export([start_link/0, init/1]). start_link() -&gt; supervisor:start_link({local, ?MODULE}, ?MODULE, _Arg = []). init([]) -&gt; {ok, {{one_for_one, 10, 10}, [{child1, {mymodule, start_link1, []}, permanent, 10000, worker, [mymodule]} , {child2, {mymodule, start_link2, []}, permanent, 10000, worker, [mymodule]} ]}}. </code></pre> <p>The <strong>worker</strong> has two distinguished start_link functions ( start_link1 and start_link2 ) for testing purposes:</p> <pre><code>-module(mymodule). -behaviour(gen_server). start_link1() -&gt; log_something("at link 1"), gen_server:start_link({global, child1}, ?MODULE, [], []). start_link2() -&gt; log_something("at link 2"), gen_server:start_link({global, child2}, ?MODULE, [], []). init([]) -&gt; .... </code></pre> <p>With the above I can see in my log the message "at link 1" but it does reveal "at link 2" anywhere. It also does not perform anything in the instance of link1 : just dies apparently. </p> <p>The only scenario that works is when the name "child1" <strong>matches</strong> the worker module name "mymodule". </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload