[erlang-questions] Using 'monitor' with spawn_opt/3 throws badarg. Documentation bug?

Roberto Aloi prof3ta@REDACTED
Tue Feb 24 08:49:55 CET 2015


I just had a quick look at the relevant source code (maint from GitHub).
Indeed, spawn_opt/3 simply calls spawn_opt/5 via erlang:apply/2, so all the
limitations of spawn_opt/5
are also valid for spawn_opt/3. See:

https://github.com/erlang/otp/blob/121b920ed5a729e69e21d8869d554d736c10f427/erts/preloaded/src/erlang.erl#L2405

Note that when you use node() as the first argument, the code path is
different and spawn_opt/2 is called instead, so you can use 'monitor' there:

https://github.com/erlang/otp/blob/121b920ed5a729e69e21d8869d554d736c10f427/erts/preloaded/src/erlang.erl#L2403

Interesting how you can still use a tuple-fun in spawn_opt/X. I thought
tuple funs were removed in R16.

https://github.com/erlang/otp/blob/121b920ed5a729e69e21d8869d554d736c10f427/erts/preloaded/src/erlang.erl#L2407

Regarding execution of funs in remote nodes, here is a nice reading:

http://www.javalimit.com/2010/05/passing-funs-to-other-erlang-nodes.html

Roberto


On 23 February 2015 at 16:17, Roger Lipscombe <roger@REDACTED>
wrote:

> I'm attempting to use spawn_opt/3 with a remote node, like this:
>
>     Fun = fun() -> ok end,
>     {Pid, Ref} = spawn_opt(Node, Fun, [link, monitor]).
>
> It fails with:
>
>     {badarg,
>       [{erlang,spawn_opt,
>        ['imp_server@REDACTED',erlang,apply,
>         [#Fun<erl_eval.20.80484245>,[]],
>         [link,monitor]],
>        []}
>
> Now, the documentation at
> http://www.erlang.org/doc/man/erlang.html#spawn_opt-5 says that the
> 'monitor' option is not allowed for spawn_opt/5. It says nothing about
> spawn_opt/3.
>
> Looking at the error message, it looks like spawn_opt/3 simply calls
> spawn_opt/5. Does this note about 'monitor' being unsupported need to
> be in documentation for both functions?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



-- 
Roberto Aloi
---
Website: http://roberto-aloi.com
Twitter: @robertoaloi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150224/21838a4a/attachment.htm>


More information about the erlang-questions mailing list