Erlang端口和线程安全 [英] Erlang ports and thread safety

查看:142
本文介绍了Erlang端口和线程安全的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过Erlang端口从Erlang进程调用C函数,如下所述:

I'm looking to call a C function from an Erlang process via an Erlang port, as described here:

http://www.erlang.org/doc/tutorial/c_port.html

在生产中,我需要多个Erlang进程并行调用C函数,每个进程都有一组不同的参数。

In production I will need multiple Erlang processes calling the C function in parallel, each with a different set of arguments.

我的问题是,这将是线程安全在C函数级别?

My question is, will this be thread safe at the C function level ?

该文档谈到控制Erlang进程创建一个连接进程,它听起来像是负责创建一个孤立的实例的外部程序(C函数)。

The docs talk about the controlling Erlang process creating a 'connected process', which it sounds as if is responsible for creating an isolated instance of the 'external program' (C function).

所以这听起来像C级的线程安全,但我想要100%肯定。

So it sounds like it's thread safe at the C level but I'd like to be 100% sure.

TIA

推荐答案

这可能取决于你的实现,但是对于Ports来说,答案几乎肯定是是你提到如果您正在NIF中使用NIF并使用共享内存,那么您将会对线程安全性有一些担忧。

It may depend on your implementation, but with Ports, the answer is almost definitely "yes" for the reason you mention. If you were using a NIF and using shared memory inside of the NIF, you would have some concern for thread safety.

然而,对于端口,控制进程作为序列化(如排列在一个系列中)层,意味着请求一个接一个地处理,而不是一次处理。此外,我认为(但不确定)通信协议端口使用也需要这个串行执行。

With ports, however, the "controlling process" acts as a serialization (as in arranged in a series) layer, meaning requests are handled one after the other and not all at once. Moreover, I believe (but do not know for certain) that the communication protocol ports use also requires this serial execution.

这篇关于Erlang端口和线程安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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