使用应用程序域并行非线程安全的DLL

使用应用程序域并行非线程安全的DLL

本文介绍了使用应用程序域并行非线程安全的DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的.net应用程序经由p使用非托管C ++ DLL /调用。我需要从这个DLL的方法是相当耗费时间,我想并行方法调用。问题是,它采用了一堆静态和全局变量,所以它不是线程安全的(且不能更改)。我的计划是通过调用多个AppDomain非托管DLL平行克服这种非线程安全的问题。

I have an unmanaged C++ DLL that my .NET application uses via p/invoke. The method that I need from this DLL is fairly time consuming and I would like to parallelize the method calls. The problem is that it uses a bunch of statics and globals, so it is not thread-safe (and can't be changed). My plan was to overcome this non-thread-safe issue by calling the unmanaged DLL from multiple AppDomains in parallel.

我可以调用从多个AppDomain非托管code,没有任何问题,只要我不这样做并行,但只要我做并行的电话,我得到一个 AccessViolationException 。我使用的Parallel.For(),使并行调用。

I can call the unmanaged code from the multiple AppDomains without any problems as long as I don't do it in parallel, but as soon as I make the calls in parallel, I get an AccessViolationException. I am using Parallel.For() to make the parallel calls.

是否有可能使一个非线程安全的非托管的DLL线程安全通过简单地实现从多个AppDomain的电话?

Is it possible to make a non-thread-safe unmanaged DLL "thread-safe" by simply making the calls from multiple AppDomains?

推荐答案

调用多个本地方法的AppDomain 情况下,不会帮助你的一切都在这里。 的AppDomain 界限并不适用于本机DLL的,他们将不会提供任何好处

Calling the native method from multiple AppDomain instances won't help you at all here. AppDomain boundaries don't apply to native DLL's and they won't provide any benefit

这篇关于使用应用程序域并行非线程安全的DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 07:04