In JNI development, it is sometimes encountered in the case of creating small threads on Layer c. In essence, Java threads and C threads are all request Kerner, just a sequence of executions. From this point of view, threads are no different, Java threads and C threads can be common.
However, there is a special place in the JNI mechanism in which each Java thread assigns a JNIEnv object to the C layer when it accesses it by JNI, and each thread is given a exclusive access. This object is used to request the VM, so it is necessary to operate the Java layer and go to the Java layer. For a thread created on the local C layer, the JNIEnv object is not given a jni, how does it communicate with the Java layer?
The answer is to register a JNIEnv object directly with the VM through the VM pointer. The code is as follows:
Jvm->attachcurrentthread (&env,null);
To create a thread code locally:
Pthread T_thread;
void *trrun (void *)
{//code}
int th1 = Pyhread_create (&t_thread,null,trrun,null);
JNI local thread into layer C