[erlang-questions] How to structure a manager/worker structure
Thu Jun 14 11:20:40 CEST 2007
You can't talk to the supervisor while it is busy starting
a process, since the start procedure is synchronous.
One way to solve it is to generate child start specifications
for the manager _and_ the workers in the supervisor's
A better way might be to have the supervisor start
first a simple_one_for_one supervisor for the workers,
and then the manager. The manager can then call
on the simple_one_for_one supervisor to start the
workers, which, presumably only differ in the start
2007/6/14, paul erlang <pc.erlang@REDACTED>:
> I am trying to set up a structure where I have some generic workers
> (gen_server processes
> driving ports) and a manager (another gen_server process.)
> The manager is responsible for creating the workers and assigning work
> to them, as required (there is a queue of work handled by the
> I would like all this to be supervised by one supervisor. I thought of
> doing it the following way:
> 1. Add the manager "statically" when creating the manager_supervisor.
> 2. Pass the manager_supervisor pid as a parameter to the manager, for
> the manager's initialization procedure.
> 3. In the manager "init" method, I want to do as many "start_child" as
> required on the same supervisor that is overseeing the manager. This
> would allow me to have the manager static in the supervisor and the
> "workers" dynamic.
> However, if I call "start_child" from the manager's "init", the system
> locks when "start_child" is executed.
> Is there any limitation against calling "start_child" on a supervisor,
> while the supervisor is initializing another child process?
> If so, what is the best way to accomplish what I am trying to do here?
> Should I have a process that is executing the "start_child" for the
> workers in one second (to allow the supervisor to finish the
> initialization of the static children)?
> Or am I approaching all this in the wrong way? As you can guess, I'm
> somewhat of a newbie, trying to understand both Erlang and OTP.
> erlang-questions mailing list
More information about the erlang-questions