문제

Say I'm working with some simple processes in erl:

1> Fun = fun(F) -> F(F) end.
#Fun<erl_eval.6.82930912>
2> Pid = spawn(fun() -> Fun(Fun) end).
<0.178.0>
3> f(Pid).

What happens when I do f(Pid).? Does the process exit or do I just lose my reference to it?

도움이 되었습니까?

해결책

According to documentation f(Pid) removes the binding of variable Pid, the process is not stopped.

You can test it in this way: suppose you have a gen_server called myserver which is based on the skeleton provided by emacs erlang mode.

1> {ok, Pid} = myserver:start_link().
{ok,<0.39.0>}
2> f(Pid).
ok
3> gen_server:call(pid(0,39,0), mycall).
ok
4> gen_server:call(myserver, mycall).
ok

As you can see even though we did f(Pid) we can still contact the process using its pid or the atom used during registration (in our case the module name).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top