[erlang-questions] Why does compile:forms spawn a linked process?

Jeremy Heater jeremy.heater@REDACTED
Fri Aug 3 14:40:33 CEST 2012


Hello everyone,

We've been using compile:forms to create a dynamically generated
module, and while testing we realized -  after we started receiving
unexpected process death notifications {'EXIT', Pid, normal} - that it
spawns a linked process.

Compile module code in question:

> forms(File) -> forms(File, ?DEFAULT_OPTIONS).
>
> forms(Forms, Opts) when is_list(Opts) ->
>     do_compile({forms,Forms}, [binary|Opts++env_default_opts()]);
> forms(Forms, Opt) when is_atom(Opt) ->
>     forms(Forms, [Opt|?DEFAULT_OPTIONS]).
>
> do_compile(Input, Opts0) ->
>     Opts = expand_opts(Opts0),
>     Self = self(),
>     Serv = spawn_link(fun() -> internal(Self, Input, Opts) end),
>     receive
>     {Serv,Rep} -> Rep
>     end.
>
> internal(Master, Input, Opts) ->
>     Master ! {self(), try internal(Input, Opts)
>               catch error:Reason -> {error, Reason}
>               end}.


Is there a particular reason spawn_link is used here instead of
calling internal(Input, Opts) directly? For our application it is less
practical, but is there some reason justifying its use?

Best regards,

Jeremy Heater.



More information about the erlang-questions mailing list