Supervisor shutdown
Raimo Niskanen
raimo@REDACTED
Tue Nov 25 12:42:24 CET 2003
The idea of tossing around a State variable in the gen_server is to
store such things as a pid() for a reply. State is commonly a record, so
just add a field. Using the process dictionary is more "ugly", since it
is used by e.g the gen_server code itself.
If your worker processes have such an intircate protocol with the
gen_server you might think about if they should form a supervision tree
of their own, and your current gen_server should be a supervisor. It is
a common tactic to not let the worker processes trap exit, and just get
instantly killed when the gen_server exits, provided you can make them
stupid enough. Making a new supervision tree is probably too heavy, though.
--
/ Raimo Niskanen, Erlang/OTP, Ericsson AB
HEINRICH VENTER wrote:
>> -the gen_server has been set to trap exit signals, and
>
> I seem to have missed this bit. Now that it traps the exit signals with
>
> process_flag(trap_exit, true)
>
> Everything works out smoothely, or rather more smoothely.
>
> I have a spanner to throw in the works now however :)
>
> The gen_sever spawns some worker processes that need to be termianted. These processes might not terminate immediately when the stop message is sent to them. (I have discovered a falw in the curent design but will post to a separate thread about this) The gen_server can not terminate before all its workers have terminated in an orderly fasion, BUT since the stop function executes in a handle_call and the workers notify the gen_server of their termination through a different handle_call.
> This brings me to the {noreply, State} mentioned in another thread.
> How do I know the PID where to send the response at the later time when I am ready to quit? The process dictionary perhaps? Then use the function that notifies the gen_server of the process termination to check if all the processes are down and then reply with the {stop, normal, ok, State} message instead of {reply, State}
> Does this make sense?
>
> -]-[einrich
>
> #####################################################################################
> The information contained in this message and or attachments is intended
> only for the person or entity to which it is addressed and may contain
> confidential and/or privileged material. Any review, retransmission,
> dissemination or other use of, or taking of any action in reliance upon,
> this information by persons or entities other than the intended recipient
> is prohibited. If you received this in error, please contact the sender and
> delete the material from any system and destroy all copies.
> #####################################################################################
More information about the erlang-questions
mailing list