[erlang-questions] Monitor vs. Link

Ulf Wiger (TN/EAB) <>
Fri Apr 4 12:02:07 CEST 2008


One very nice aspect of link is "cascading exits",
which allows you to spawn as many processes as you need
and have only a few of them trap exits. The others will
simply go away when the 'master' goes.

Without this, you may sometimes hesitate to create
extra processes, since they all have to do explicit
cleanup.

BR,
Ulf W

Dave Smith skrev:
> So I was sent a link to a talk done by Bob Ippolito (nice to put a
> name with the face) :)
> 
> http://www.viddler.com/explore/rentzsch/videos/8/
> 
> In that video, Bob makes a glancing comment along the lines of:
> 
> "...you'll only see process_flag(trap_exit, true) in old code.
> Typically you will use monitoring instead..."
> 
> This is interesting to me as I recently found myself using links +
> trap_exit amongst some related processes and I wondered if the "Right
> Way" would have been to use monitors instead. I do have a
> bi-directional relationship between processes -- if one dies I want
> the other to also (typically) do some shutdown. I could accomplish the
> same thing with two monitors, but it seems like more work overall.
> 
> So, here's my question -- is there a reason to prefer using two
> monitors to create a bi-directional monitor over link + trap_exit?
> What's the best practice, particularly when one considers that I'm
> using OTP patterns (gen_server and gen_fsm)?
> 
> Thanks,
> 
> D.
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list