Linking to/from a gen_server?

Lennart Öhman lennart.ohman@REDACTED
Sun Mar 2 11:34:29 CET 2003


Hi,
your concerns are valid. However...:

1) In the early beginning of BOS (OTP ancestor) we choose to use
    a time-out *only* in gen_server:call. One reason was what you
    described. But the other was that internal handling of links
    (the structure it was stored in) was not built for having a
    lot of links and at the same time manage them frequently.

2) Nowdays there is another mechanism - erlang:monitor which
    monitors the existance of "things". Today the only "thing"
    which can be monitored is another process.
    Monitoring has two significant differences to links.
    (i)  Monitoring is *not* bi-directional.
    (ii) Monitoring results in as many DOWN-messages as monitoing
         has be been called. Very good for writing library code
         for instance.

Today, to my knowledge, all OTP gen-code has been rewritten in
"modern style" using monitoring instead.

Hence you may very well implement your solution as have your gen-server
monitor the client PID, and be responsive (in handle_info) to
DOWN-messages from such PIDs.

/Lennart


Shawn Pearce wrote:
> Ok, so I'm trying to use OTP stuff as much as I can right now, as I
> haven't really learned it all yet.  :)
> 
> I'm trying to setup a way to have a client process send a gen_server
> a message, where the gen_server stuffs a term and the client's pid
> into an ets table managed by the gen_server.  I want the gen_server
> to link to the client process so it can remove the term and client
> pid when the client process exits.
> 
> But it occured to me, gen_server:call/2 links to the gen_server
> process, sends the message, and waits for the response with a
> timeout.  It then unlinks from the gen_server.  This means the
> gen_server can't link to the client process during its handle_call/3
> callback, as the unlink will be done by the client after the call
> completes.
> 
> I could use gen_server:cast/2, but i do need a response to be sent
> back to the client so it knows the operation was successful.
> 
> Ideas from the OTP experts?
> 


-------------------------------------------------------------
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