[erlang-questions] Monitor option in spawn_opt/5

Ulf Wiger ulf@REDACTED
Mon Jul 29 15:49:41 CEST 2013

It shouldn't be the need for atomicity as much as a convenience and - in the case of remote spawn - an optimization.

On R15B, it works as you'd expect:

Erlang R15B (erts-5.9) [source] [64-bit] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9  (abort with ^G)
1> spawn_opt(fun() -> io:fwrite("hi~n",[]) end, [monitor]).
2> flush().
Shell got {'DOWN',#Ref<>,process,<0.33.0>,normal}

Same on R16B, as far as I can tell.

Ulf W

On 29 Jul 2013, at 13:54, Michał Ptaszek <erlang@REDACTED> wrote:

> I'm not sure if spawn and monitor have to be atomic though. If we set up a monitor on non-existing/exiting process 'DOWN' message is going to be delivered to the caller anyway ("A 'DOWN' message will be sent to the monitoring process if Item dies, if Item does not exist, or if the connection is lost to the node which Item resides on.", http://www.erlang.org/doc/man/erlang.html#monitor-2). 
> It's not a big deal for me to spin up a monitor on my own, however it would be good to know if I miss something or should code/documentation be fixed.
> On Sat, Jul 27, 2013 at 1:03 PM, Motiejus Jakštys <desired.mta@REDACTED> wrote:
> On Sat, Jul 27, 2013 at 1:05 PM, Michał Ptaszek <erlang@REDACTED> wrote:
> > Hey,
> >
> > What is the reason for not allowing to pass 'monitor' option to processes
> > spawned by erlang:spawn_opt/5?
> >
> > The code inside of erlang.erl states:
> >
> >     case lists:member(monitor, O) of
> > false -> ok;
> > true -> erlang:error(badarg, [N, M, F, A, O])
> >     end,
> >
> > However the documentation does not clarify anything.
> > Setting up a monitor on the returned pid right after spawn works fine
> > though.
> I guess the reason is that there is no way in Erlang to atomically
> spawn and monitor the pid on another node. Though it's a bit strange
> that [link] works on remote nodes, but [monitor] doesn't. Anyone care
> to explain why?
> --
> Motiejus Jakštys
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130729/9dcbf031/attachment.htm>

More information about the erlang-questions mailing list