Java:在两个线程中加载相同的动态库(同一个JVM中的两个线程) [英] Java: Load the same dynamic library in two threads (both threads in the same JVM)

查看:93
本文介绍了Java:在两个线程中加载相同的动态库(同一个JVM中的两个线程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用不可重入的库(用C编写)(即库中的函数不可重入)。假设我已经通过System.load加载库来获取句柄'v'。由于可重入问题(尝试但无效的结果),我无法在两个线程中使用v。我可以使用锁,但是会失败我可以获得的任何并行性。

I am using a library (written in C) that is not reentrant(i.e no function in the library is reentrant). Suppose I have loaded the library via System.load to get the handle say 'v'. I cannot use v in two threads because of the reentrancy issues (tried but nonsense results). I could use locks, but that defeats any parallelism i could have gained.

我想做的是启动两个线程,并在每个线程中加载库得到两个不同的句柄(因此有两个加载库的副本)。

What I'd like to do is start two threads, and in each thread load the library to get two different handles(thus there are two copies of the loaded library).

这是可能在Java中吗?
Regards
Saptarshi

Is this possible in Java? Regards Saptarshi

推荐答案

任何DLL只能通过一个进程加载一次,认为你可以实现你想要的。你可以欺骗和重命名DLL到一个不同的名字吗?

Any DLL can be loaded only once by a process, so I don't think you can achieve what you want. You could cheat and rename the DLL to a different name maybe?

你的线程花了这么多时间在DLL中没有其他的并行性?

Your threads spend so much time in the DLL that there is no other parallelism to be had?

这篇关于Java:在两个线程中加载相同的动态库(同一个JVM中的两个线程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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