You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To me it seems we are lazily attaching to the current thread and caching the result in a thread_local JNIEnv* but there's no corresponding call to DetachCurrentThread.
"""
Threads attached through JNI must call DetachCurrentThread() before they exit. If coding this directly is awkward, in Android 2.0 (Eclair) and higher you can use pthread_key_create() to define a destructor function that will be called before the thread exits, and call DetachCurrentThread() from there. (Use that key with pthread_setspecific() to store the JNIEnv in thread-local-storage; that way it'll be passed into your destructor as the argument.)
"""
So it seems that we
should first detect whether current thread is attached
use AttachCurrentThread() which may be a NOP if it's already attached
if we were not attached before, we should use the pthread key approach mentioned above to install a destructor that calls DetachCurrentThread()
The text was updated successfully, but these errors were encountered:
To me it seems we are lazily attaching to the current thread and caching the result in a
thread_local JNIEnv*
but there's no corresponding call toDetachCurrentThread
.See JNI tips:
"""
Threads attached through JNI must call DetachCurrentThread() before they exit. If coding this directly is awkward, in Android 2.0 (Eclair) and higher you can use pthread_key_create() to define a destructor function that will be called before the thread exits, and call DetachCurrentThread() from there. (Use that key with pthread_setspecific() to store the JNIEnv in thread-local-storage; that way it'll be passed into your destructor as the argument.)
"""
So it seems that we
AttachCurrentThread()
which may be a NOP if it's already attachedDetachCurrentThread()
The text was updated successfully, but these errors were encountered: