我正在阅读Joe Armstrong撰写的“编程Erlang”。他提到,如果我们将spawn
spawn_link
register
放在一起,则可能会导致竞争条件,因为讨论代码如下:
keep_alive(Name, Fun) ->
register(Name, Pid=spawn(Fun)),
%% he says that process may die between these two code
%% he also says that if two process use the same "Name" and call "keep_alive"
%% at the same time, it will cause the competition and make the process died
%% here(but I am not totally understand here).
on_exit(Pid, fun(_why) -> keey_alive(Name, Fun) end).
任何可以解决此问题的解决方案?