A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/bytedeco/javacpp/issues/737 below:

Potential class loading deadlock when call static methods of Loader or Pointer · Issue #737 · bytedeco/javacpp · GitHub

We observed a problem when calling a utility function like Loader.isLoadLibraries (which calls Loader.load() when this is the first access) in one thread while running e.g. Pointer.maxBytes() in another thread:

// thread 2
public class PrintMaxBytes implements Runnable {
	@Override
	public void run() {
		long l = org.bytedeco.javacpp.Pointer.maxBytes();
		System.out.println(l);
	}
}
var t = new Thread(new PrintMaxBytes ());
t.start();

// thread 1(calls Loader.load())
Loader.isLoadLibraries();

The reason seems to be that in the JNI code there is

jclass cls = (jclass)env->CallStaticObjectMethodA(JavaCPP_getClass(env, 0), putMemberOffsetMID, args);

which basically calls the static method Loader.putMemberOffset and by doing so triggers another call to Loader.load() for which the other thread already has a lock.

In our case we solved the issued by doing e.g. new Pointer(0) in an early part of the code where we are sure we still have only one thread.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4