when we attach a Cpp thread to the Java Native Interface (JNI) using the AttachCurrentThread (JavaVM *vm, void **p_env, void *thr_args) method, the C++ thread effectively becomes an external thread from the perspective of the Java Virtual Machine (JVM).
After Attaching the Native Cpp thread to JVM, if I do pthread_join on the attached thread or if the attached thread is abruptly terminated before getting Detach from JVM, Is there going to be an issue?
what I understand is when a native thread is attached to the JVM using AttachCurrentThread, the JVM allocates certain resources and maintains internal data structures to manage the thread's interaction with Java objects. If the thread is abruptly terminated without being properly detached, these resources may not be released and could lead to memory leaks or other resource or JVM-related issues.
In the above code DeattachCurrentThread becomes unreachable and I have already did pthread_exit (), will this cause any issue related to memory leak or any other issue?
Is it safe to do pthread_join on a thread that has been attached to JVM using JNI's AttachCurrentThread method
There is no particular reason to think not. Java and JNI have no more means to interfere with the thread than any other code has.
Note, too, that the JNI specifications require a thread that attaches to a JVM to detach itself again before terminating. After such a detachment, there is especially no reason to think that the thread would exhibit any behavior inconsistent with pthreads.