Silly Qn': Process exits at spawn
Bengt Kleberg
Bengt.Kleberg@REDACTED
Tue Oct 14 10:42:07 CEST 2003
chris.danx wrote:
> Thanks folks, it runs now!
>
> Can anyone help with another problem? I've probably done something
> stupid again. The following code is supposed to query the server if a
> neuron with the given name exists and if it does, return false. If the
> neuron doesn't exist, it creates a new neuron one (a process) and
> returns. The problem I'm having is finding where abouts the hang
> occurs. Does anyone have any tips for debugging Erlang?
see the manual page for module ''dbg''.
> I think it fails to receive the {Reg, Exists} message in create neuron,
> but I could be wrong.
>
>
> %% create a neuron
> %
> create_neuron (Name, State, OutputFunc) ->
> neural_registry ! {self(), exists, Name},
> receive
> {Reg, Exists} -> if Exists == true ->
> false;
> true ->
> {X, Pid} = neurons:create_neuron(Name, State, OutputFunc),
> add_neuron_to_reg ({X, Pid})
> end
> end.
for the sake of simplicity i think you could re-write this as:
create_neuron(Name, State, Output) ->
neural_registry ! {self(), exists, Name},
receive
{_From, true} ->
false;
{_From, false} ->
{X, Pid} = neurons:create_neuron(Name, State, Output),
add_neuron_to_reg({X, Pid})
end
end.
bengt
More information about the erlang-questions
mailing list