且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Erlang中发送大消息时,是否有引发竞争条件的风险?

更新时间:2022-05-16 07:58:04

消息接收是原子操作.

如果您对完成方法感兴趣,请阅读VM的源代码.如果简化一下,发送过程将执行以下步骤:

If you are interested how it is done, read the source code of VM. If I simplify it, the sending process is doing those steps:

  1. 在发送过程中分配目标内存空间(称为环境).
  2. 将消息复制到该存储空间
  3. 对目标进程进行外部锁定
  4. 将邮件链接到邮箱链接列表
  5. 释放对目标进程的外部锁定

如您所见,复制是在关键部分之外(之前)完成的,并且关键部分的速度非常快.只是在玩弄很少的指针.

As you can see, copying is done outside (before) critical section and the critical section is pretty fast. It is just juggling with few pointers.