【问题标题】:Erlang message to non-existent PIDErlang 消息到不存在的 PID
【发布时间】:2015-02-10 20:08:44
【问题描述】:

Erlang 运行时如何处理发送到不存在的进程的消息?例如,一个进程被生成,然后在它终止后另一个进程向它发送消息。

【问题讨论】:

    标签: erlang


    【解决方案1】:

    消息被丢弃。每the documentation

    如果接收端已经终止,信号就不会到达……

    另见this answer from rvirding,他可能知道他在说什么:

    虽然向一个指向死进程的 pid 发送消息是完全合法的(消息只是消失了)...

    【讨论】:

      【解决方案2】:

      如果消息被发送到一个 PID,那么消息将消失在 void 中。您甚至可以发送到不存在的 PID...

      1> list_to_pid("<0.0.1>").
      <0.0.1>
      2> v(1) ! foo.
      foo
      

      如果消息是发送给原子,原子必须是发送时的某个PID的注册名,否则发送会崩溃……

      3> spawn(fun() -> register(name, self()), then_exit end).
      <0.36.0>
      4> name ! foo.
      ** exception error: bad argument
           in operator  !/2
              called as name ! foo
      

      【讨论】:

        猜你喜欢
        • 2016-11-13
        • 2014-11-30
        • 2011-05-07
        • 1970-01-01
        • 2014-09-17
        • 2012-03-03
        • 1970-01-01
        • 1970-01-01
        • 2015-04-07
        相关资源
        最近更新 更多