Silly Qn': Process exits at spawn

chris.danx chris.danx@REDACTED
Mon Oct 13 21:35:14 CEST 2003


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?

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.


%% add neuron to registry
%
add_neuron_to_reg ({Name, Pid}) ->
     neural_registry ! {self(), add, {Name, Pid}},
     receive
	{Reg, Succ} ->
	    Succ
     end.

registry_loop(Val) ->
     receive
	% add neuron to list
	%
	{From, add, {Name, Pid}} ->
	    P = [{Name, Pid}] ++ Val,
	    From ! {self(), true},
	    registry_loop (P);

	%
	%
	{From, remove, Name} ->	
	    {X, P} = get_neuron_and_remaining (Val, Name, []),
	    if X == nil ->
		    From ! {self(), false};
	       true ->
		    From ! {self(), true}
	    end,
	    registry_loop (X);

	% retrieve registered neurons
	%
	{From, reg_neurons} ->
	    From ! {self(), Val},
	    registry_loop (Val);

	% return true if neuron exists, false otherwise
	%
	{From, exists, Name} ->
	    From ! {self(), false},
	    registry_loop (Val);

	% stop registry.
	%
	stop ->
	    true;
	
	% just loop.
	%
	Other ->
	    registry_loop (Val)
     end.


Cheers,
Chris




More information about the erlang-questions mailing list