Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Loading library in/on main thread #1652

Open
szsoftware opened this issue Feb 1, 2025 · 0 comments
Open

Loading library in/on main thread #1652

szsoftware opened this issue Feb 1, 2025 · 0 comments

Comments

@szsoftware
Copy link

I encountered the following issue with Ubuntu Linux/openjdk/Kotlin/Rust development:

I'm loading a uniffied Rust libexample.so in the main thread of my console application.

So far I thought and learned, that native code loaded in the main thread is executed in the main thread.

But, after a lot of examination on the Rust, the Java/Kotlin and the os side, I found out that the NativeLoading procedures produces a second os-thread for the java process, always consecutive to the main thread and with an offset of 4.

On the rust side, this has implications: windowing (winit) does a main thread check and it will fail because processId != threadId, and we all know that the main threadId = processId.

Having the library running on another thread can also have implications for OpenGl context sharing or things like this.

However, is it possible to omit a second jna thread and let the library functions execute in exactly the context of the java main thread (and it's OS counterpart)?

Thank you for some clarification!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant