对来自 VB.NET 的非托管 DLL 调用强制使用特定的处理器关联
我正在从 VB.NET Web 服务器调用一个函数到自定义编写的非托管 DLL。 如果我们通过多核服务器上的 Web 服务调用这个 DLL,我们就会遇到问题并且它总是会崩溃。
如果我重新启动服务器并使其仅使用单核,它总是运行良好并且永远不会崩溃。
我知道 DLL 调用是导致崩溃的原因,因为我在 DLL 调用之前和之后输出了调试代码。
我可以将 .NET 代码的处理器关联强制为 1 个核心,但这不适用于非托管 DLL。
我如何强制非托管 DLL 仅在单个核心上运行,因为我确信这会解决问题?
I am calling a function from a VB.NET webserver to a custom written unmanaged DLL.
If we call this DLL via a webservice on a multi-core server we run into problems and it always crashes.
If I reboot the server and make it only use a single-core, it always runs fine and never crashes.
I know the DLL call is responsible for the crash as I have outputted debugging code just before and after the DLL call.
I can force the processor affinity of the .NET code to 1 core but this doesn't apply to the unmanaged DLL.
How can I force the unmanaged DLL to only run on a single core as I am sure this will solve the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有权访问 DLL 代码,那么您可以在 DllMain 中使用类似以下几行的内容:
DWORD_PTR processAffinityMask = 0x1;
SetProcessAffinityMask( GetCurrentProcess(), processAffinityMask );
这会将 dll 的进程亲和力设置为第一个 CPU。
If you have access to the DLL code then you can use something like the following lines in DllMain:
DWORD_PTR processAffinityMask = 0x1;
SetProcessAffinityMask( GetCurrentProcess(), processAffinityMask );
This will set the process affinity of the dll to the first CPU.