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

Process 如果我们将它们放在erlang中,为什么spawn spawn_链接寄存器可能会导致竞争条件?,process,concurrency,erlang,Process,Concurrency,Erlang,我正在读乔·阿姆斯特朗的《编程二郎》。他指出,如果我们将spawnspawn\u链接寄存器放在一起,在讨论以下代码时,可能会导致竞态条件: 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 "Na

我正在读乔·阿姆斯特朗的《编程二郎》。他指出,如果我们将
spawn
spawn\u链接
寄存器
放在一起,在讨论以下代码时,可能会导致竞态条件:

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).
有什么解决办法吗?

看看这个回答:可能是重复的