Matlab引擎API的线程安全 [英] Thread safety of Matlab engine API

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

问题描述



我已经通过试验和错误发现MATLAB引擎函数不是完全线程安全的。



通过尝试和错误发现:



在Windows上,与MATLAB的连接是通过COM,因此COM公寓线程规则适用。所有调用必须发生在同一个线程中,但多个连接可以发生在多个线程中,只要每个连接都是隔离的。



从下面的答案,

解决方案

当我调用时,可以从多个线程调用。首先开始使用引擎,我没有运行任何关于线程安全的文档,所以我认为它不是线程安全的。



我使用C ++类同步对引擎实例的访问。对于更多的并行处理设计,我实例化引擎类的多个实例。



(编辑)我在Solaris上使用MATLAB R14。我使用engOpen调用打开引擎,并使用engClose关闭它。我的平台不会崩溃,当Close是由一个不同的线程调用,而不是调用Open。​​


I have discovered through trial and error that the MATLAB engine function is not completely thread safe.

Does anyone know the rules?

Discovered through trial and error:

On Windows, the connection to MATLAB is via COM, so the COM Apartment threading rules apply. All calls must occur in the same thread, but multiple connections can occur in multiple threads as long as each connection is isolated.

From the answers below, it seems that this is not the case on UNIX, where calls can be made from multiple threads as long as the calls are made serially.

解决方案

When I first started using the engine, I didn't run across any documentation on thread safety, so I assumed that it was not thread-safe.

I use a C++ class to synchronize access to an engine instance. For more parallel processing designs, I instantiate multiple instances of the engine class.

(edit) I'm using MATLAB R14 on Solaris. I open the engine using the 'engOpen' call, and close it using 'engClose'. My platform does not crash when the Close is called by a different thread than the one that called Open.

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

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