Erlang如何处理并发访问邮箱 [英] How Erlang processes access mailbox concurrently

查看:203
本文介绍了Erlang如何处理并发访问邮箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于如何使用erlang邮箱的信息很多,但是很少找到论文或文档来描述erlang在VM内部如何同时访问实际邮箱.

There are lots of info regarding how to use erlang mailbox, but seldom to find a paper or document describe how erlang actual access mailbox concurrently internally within the VM.

据我了解,Erlang VM必须执行锁定或CAS操作才能确保消息完整性. erlang的幕后有什么复杂的方法

To my understanding, Erlang VM must have to do locking or CAS action to secure message integrity. Is there any sophisticate way of method behind erlang's curtain

推荐答案

通过邮箱我假设您是指流程邮箱,一条消息已插入其中.好玩的问题!

By mailbox I'm assuming you mean the process mailbox, the one messages are inserted into. Fun question!

此处上有一些对话.处理消息队列:

There's some conversation here about the locking characteristics of the Erlang process message queue:

只是出于好奇:目前在发送消息时存在某种形式的锁定. 是否有人尝试实现无锁链接列表: http://www.amd64.org/fileadmin/user_upload/pub/epham08-asf- eval.pdf

Just a curiosity: currently there is some kind of locks in sending message. Have anybody tried to implement a lock-free linked list: http://www.amd64.org/fileadmin/user_upload/pub/epham08-asf-eval.pdf

或者我只是在看错地方,并且erts_smp_proc_lock已经 使用这样的东西?

Or I'm just looking at wrong place and erts_smp_proc_lock is already using something like this?

消息队列中已经有这个了.拥有 消息框上有一个内盒",他已锁定并在外盒"上 所有发件人争夺的盒子".因此,锁争用在 当许多进程发送到外部框"时,队列的尾部 这个过程.邮箱所有者对此并不关心.

The message queue already has this, sort of. The process that owns the message box has an "inner box" that he has a lock on and an "outer box" that all senders compete for. So the lock contention is on the tail of the queue on the "outer box" when lots of processes sends to that process. The mail box owner is not concerned with it though.

您可能会发现阅读 BEAM流程的说明性实施.

You might find reading the implementation of the BEAM process illustrative.

简短的回答:是的,锁定是在消息队列上完成的,但是它很复杂并且经过优化,可以减少调度程序线程之间的争用.

Short answer: yes, locking is done on the message queue, but it's complicated and optimized to reduce contention between scheduler threads.

这篇关于Erlang如何处理并发访问邮箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆