erlang 什么是BEAM中的同步调用技巧/引用技巧

mpgws1up  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(200)

我们最近作为阅读小组的一员阅读了X1 E0 F1 X。在第7章中有一个关于Erlang中的ref技巧/同步调用技巧的典故。
不幸的是,这本书是不完整的,经过讨论,我们无法弄清楚裁判的伎俩是。

ny6fqffe

ny6fqffe1#

When performing a receive , the BEAM VM scans the mailbox in order to find the first suitable (matching) message, and blocks the process if it does not find any.
The 'trick' is that, since it's impossible for a new reference to be in the mailbox before it was created, there's no need to scan the whole mailbox when receive {Reference, Term} , only from the point where Reference was created.
That's the meaning of the following phrase:
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.

相关问题