Silly Qn': Process exits at spawn

Sean Hinde sean.hinde@REDACTED
Mon Oct 13 18:56:23 CEST 2003


You are starting your process with a none existing registry_loop/0.

If you have sasl running, and use proc_lib:spawn, rather than spawn you 
get nice error messsages.

Sean

On Monday, October 13, 2003, at 05:31  pm, chris.danx wrote:

> 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