[erlang-questions] Attempting to create a plethora of processes

Dave Vandervies dj3vande@REDACTED
Sun Jul 12 06:40:43 CEST 2009


Somebody claiming to be Yves S. Garret wrote:
> Hi all,
> 
>    I'm just trying to get a better unerstanding of IPC in Erlang and I
> stumbled on this little problem.  The problem arises when I get to the
> spawn method.  My present understanding is that the spawn method will
> create a different process with the passed in method and then
> immediately return.
[...]
>         However,
> what throws me for a loop is the fact that the process that called the
> spawn method seems to be unresponsive.  This was not my intention and
> don't understand why this would happen.  What have I misunderstood?
> spawn creates a new process, so in theory, it should just exit out of
> that method and proceed with the parent...

The problem isn't with spawn itself, it's with the argument you're
giving it.

You have:
>   Pid = spawn(simulate()),
which calls simulate, and then calls spawn with whatever simulate returns
(except you're not getting that far, since simulate blocks in a receive.)

Try saying:
    Pid = spawn(fun simulate/0),
instead; this will give spawn the function simulate/0 as an argument,
and spawn should kick off a new process and return as you expect.


dave

-- 
Dave Vandervies
dj3vande@REDACTED

Plan your future!  Make God laugh!


More information about the erlang-questions mailing list