gen_server

Martin J. Logan mlogan@REDACTED
Tue Dec 16 00:35:33 CET 2003


On Mon, 2003-12-15 at 17:04, Inswitch Solutions - Erlang Evaluation
wrote:
> Hi Lennart,
> 
> Suppose Pid0 is the gen_server Pid
> 
> I execute in two different processes (clients):
> - Pid1 gen_server:call to Pid0 gen_server
> - Pid2 gen_server:call to Pid0 gen_server
> 
> Is the gen_server blocked while processing Pid1 or Pid2 request?

The gen server is a single process i.e a single "thread". Consequently
if you make a call from pid1 the gen server is going to service that
request and send back a response before it ever pulls the request sent
by pid2 out of its(pid0) mailbox. This is assuming that the request made
by pid1 got arrived in the mailbox of pid0 first. Basically the first
request will be totally serviced and the the second request will be
serviced in the same manner. 

> 
> The pattern is clients calling a server, so the implementation of gen_server
> (behavior) should resolve this problem in some way (spawning processes for
> each client sync. request for example).
> As far as I know this is what OO design patterns implementation are supposed
> to solve. Does OTP behavior in Erlang mean the same as OO design patterns?
> 

This is not what the gen_server should do, and it is in fact what it
does not do:-)  The gen server is a just a loop that receives messages
and executes user specific code sequentially for each message. If you
want to solve the problem that you speak of it sounds like you want a
few gen_* type processes. Think concurrent tcp server. One "listener"
that spawns a handler for each concurrent connection. That sounds like
what you want.

Cheers,
Martin

> Thanks again,
> Eduardo Figoli
> 
> 
> 
> 
> 
> 
> 
> 
> ----- Original Message -----
> From: "Lennart Öhman" <lennart.ohman@REDACTED>
> To: "Inswitch Solutions - Erlang Evaluation" <erlang@REDACTED>
> Cc: <erlang-questions@REDACTED>
> Sent: Monday, December 15, 2003 7:48 PM
> Subject: Re: gen_server
> 
> 
> > A client making a request using gen_server:call (hopefully
> > hidden in an API function) waits until a response is sent
> > back from the gen_server process. That response (message)
> > makes the gen_server:call function return a return value.
> >
> > /Lennart
> >
> > Inswitch Solutions - Erlang Evaluation wrote:
> >
> > > When calling gen_server:call, does it blocks the gen_server process?
> > >
> > > From another point of view does gen_server solve the pattern of multiple
> > > clients requests calling in a synchronous way (gen_server:call)?
> > > For each client a process should be spawned.
> > >
> > > Thanks,
> > > Eduardo Figoli
> > >
> > >
> >
> > --
> > -------------------------------------------------------------
> > Lennart Ohman                   phone   : +46-8-587 623 27
> > Sjoland & Thyselius Telecom AB  cellular: +46-70-552 6735
> > Sehlstedtsgatan 6               fax     : +46-8-667 8230
> > SE-115 28 STOCKHOLM, SWEDEN     email   : lennart.ohman@REDACTED
> >




More information about the erlang-questions mailing list