[erlang-questions] spawn race condition?

Anthony Shipman als@REDACTED
Wed Apr 4 12:50:01 CEST 2007


On Wed, 4 Apr 2007 04:05 am, Oscar Hellström wrote:
> On Wed, 4 Apr 2007 04:01:16 +1100
>
> Anthony Shipman <als@REDACTED> wrote:
> > I have code that looks like this:
> >
> > call(Phone) ->
> >     Pid = spawn(?MODULE, init, [Phone]),
> >
> >     util:delay(100),
> >     Pid! {startCall, self()},
> >     receive
> > 	callComplete -> {ok, Pid}
> >     after
> > 	5000 -> false
> >     end.
> >
> > If I don't have the 100ms delay then the only message that the new
> > process receives is the integer 0. It works with the delay. Am I missing
> > something?
>
> What exactly does init/1 do? You are indeed supposed to be able to send
> messages to processes without delays. Are there any other processes
> sending the spawned processes if it would return {ok, Pid}? Does init
> somehow flush the message queue?

These are good questions which led me to the bug. init was contacting another 
process which wasn't well written. Thanks for the help.

-- 
Anthony Shipman                    Mamas don't let your babies 
als@REDACTED                   grow up to be outsourced.




More information about the erlang-questions mailing list