Silly Qn': Process exits at spawn

chris.danx chris.danx@REDACTED
Mon Oct 13 18:31:14 CEST 2003


Hi,

What's wrong with this module?  I've not played with erlang in ages and 
even then only for a few days.  The problem seems to be that the 
registered process exists at spawn or very quickly but I don't 
understand why.  Can someone please tell me what is wrong?


-module(neural).
-export([create_registry/0,
	 stop_registry/0,
	 registry_loop/1,
	 add_neuron/1,
	 registered_neurons/0]).

create_registry () ->
     Pid = spawn (neural, registry_loop, []),
     register (neural_registry, Pid).


stop_registry () ->
     neural_registry ! stop.


add_neuron (Name) ->
     neural_registry ! {self(), add, Name}.


registered_neurons () ->
     neural_registry ! {self(), reg_neurons},
     receive
	{Registry, Vals} ->
	    Vals
     end.

registry_loop(Val) ->
     receive
	{From, add, Name} ->
	    registry_loop (lists:append (Val, Name));
	stop ->
	    true;
	Other ->
	    registry_loop (Val)
     end.
	

Thanks,
Chris




More information about the erlang-questions mailing list