miller
miller

Reputation: 1728

How to implement Lock in Java/C application

I have concurrency problem with Android application. Base of a problem is that Java code is trying to invoke C function and set value through JNI interface before C code is loaded. I have MainActivity.java which invokes C function and NativeLib.java which loads C shared library. Is there any elegant way to solve this concurrency problem, eg. by setting from C some Java field to true when loading is finished and locking MainActivity method until that value is true? Or maybe there is some other, better solution?

Basic principle of engine

This is a basic diagram of engine. In GLThread, in loop, method guardedRun() calls onDrawFrame() that sends JNI call to C to render frame and then, when guardedRun() receives new GL frame, it swaps frame buffer.

Problem is with method onMessageReceived(). Now, I want to connect Activity on startup with another device, and when it connects, I want to receive message that will be sent from Java to C. But the trouble is that C isn't loaded yet and Java is already up and connected. So, how does C says to Java: "wait until I'm loaded"?

Upvotes: 1

Views: 111

Answers (1)

OldCurmudgeon
OldCurmudgeon

Reputation: 65879

The obvious answer is:

Ensure the C code is loaded before invoking the C function.

We can not provide much detail in our answers until you provide detail in your question.

Upvotes: 1

Related Questions