【问题标题】:What is the Synchronous Call Trick/Ref Trick in BEAM什么是 BEAM 中的同步调用技巧/参考技巧
【发布时间】:2020-12-12 06:02:45
【问题描述】:

我们最近在阅读BEAM book 作为我们阅读小组的一部分。在Chapter 7 中提到了 Erlang 中的 ref 技巧/同步调用技巧。

很遗憾,这本书不完整,经过讨论我们无法弄清楚参考技巧是什么。

【问题讨论】:

    标签: erlang elixir beam


    【解决方案1】:

    在执行receive 时,BEAM VM 会扫描邮箱以找到第一个合适(匹配)的邮件,如果找不到,则阻止该进程。
    “诀窍”是,由于在创建新引用之前不可能在邮箱中存在新引用,因此在 receive {Reference, Term} 时无需扫描整个邮箱,只需从创建 Reference 的那一点开始。

    这就是下面这句话的意思:
    The compiler recognizes code that uses a newly created reference (ref) in a receive (see [ref_trick_code]), and emits code to avoid the long inbox scan since the new ref can not already be in the inbox.

    【讨论】:

      猜你喜欢
      • 2010-09-30
      • 1970-01-01
      • 2011-05-27
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多