[erlang-questions] what is the correct syntax to spawm a MFA with no arguments?
Thu May 1 17:53:41 CEST 2008
On Thu, May 1, 2008 at 6:04 AM, Richard Carlsson <> wrote:
> Darren New wrote:
> > I know very little about Erlang overall, but isn't the point of
> > exporting this to make it available for code upgrades? I.e., without
> > exporting the entry, it would be very difficult to have spawn(M,F,A)
> > spawn code that had changed recently, yes?
> No, because if you are using spawn(fun loop/0), or if you want to pass
> some arguments, use spawn (fun () -> loop(X, Y, Z) end), then obviously
> both the spawning code and the code for the fun is in the _same module_,
> so if the spawner is running the new code, the new process will also
> be running the new code. Code upgrade is only done per whole module.
> Also note that since the body of the fun is a tail call to the loop
> function, the fun-object is just a temporary object which is discarded
> once the new process starts executing in loop(). So, spawning from
> funs in this way is totally safe with respect to code upgrade.
> The warning about funs and code upgrade only has to do with stuff like
> storing a fun in a data structure somewhere, and then later digging it
> out and running it. It is by that time possible that the module where
> the fun was defined has been reloaded, but you'll still be running the
> old code that the fun belongs to. (You might often actually want this.)
> When you do a spawn from a literal fun for code in the same module, this
> cannot happen.
so are you saying you can do hot code reloading _without_ using the MFA
version of spawn?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions