Gen_server and multiple processes

Sean Hinde <>
Thu Dec 19 13:00:50 CET 2002


> 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?
> In other words, if several calls to the function foo() is made, will
> there be several processes each running handle_call spawned, or will
> there be several queued calls to handle_call?
> 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).

As Mattias says gen_server doesn't do this, but it does provide the mechnism
to not return an immediate reply if you wish to spawn a new thread for the
call, and an additional mechanism to actually send the reply sometime later.

You just need to return {no_reply, State} from the initial handle_call/3,
and later call gen_server:reply(Client, Reply) with the result of the long
calculation done in your thread.

Sean



NOTICE AND DISCLAIMER:
This email (including attachments) is confidential.  If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents.  We cannot accept liability for any breaches of
confidence arising through use of email.  Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions.  We will not accept responsibility for any commitments
made by our employees outside the scope of our business.  We do not warrant
the accuracy or completeness of such information.




More information about the erlang-questions mailing list