如果我们将它们放在erlang中,为什么spawn spawn_link寄存器可能会导致竞争条件?

时间:2015-02-05 09:20:17

标签: process concurrency erlang

我正在阅读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).

任何可以解决此问题的解决方案?

0 个答案:

没有答案