Gen_server and multiple processes
Fri Dec 20 10:13:27 CET 2002
* hfventer <hfventer@REDACTED> [2002-12-19 11:08:59 +0200]:
> Hello all
> I would like to know if the gen_server behavior creates a separate
> process for each message that is sent to it, or must this kind of thing
> still be written into your own code?
> It seems that playing to Erlangs strengths in this situation makes the
> most sense :) Would spawning a process to handle foo and returning
> immediately might be the correct way to do this type of thing? (if
> gen_server does not do it already).
One thing to remember is that gen_server has a state. One of the goal of
the gen_server is to protect/serialize access to this state.
So you are always sure that you will not have concurrency problem
on the state on a gen_server.
I have remarked that people that discover gen_server tend to overuse it.
One of the question to ask is: Do we need a gen_server in our case.
Sometimes a simple spawn can do the trick and the gen_server is not
You should think twice about using a gen_server especially when your
gen_server uses an empty state.
I hope this helps.
More information about the erlang-questions