Android NDK代码:
pthread_create(&msg_thread, NULL, msg_runnable, NULL);
void *msg_runnable(void *arg) {
...
pthread_detach(pthread_self());
...
pthread_exit(NULL);//crash
....
}
报错:
threadid=12:native thread exited without detaching
解决办法:
void *msg_runnable(void *arg) {
JNIEnv *env = NULL;
(*g_jvm)->AttachCurrentThread(g_jvm, &env, NULL);
...
pthread_detach(pthread_self());
...
(*g_jvm)->DetachCurrentThread(g_jvm);
pthread_exit(NULL);//crash
....
}
http://stackoverflow.com/questions/26534304/android-jni-call-attachcurrentthread-without-detachcurrentthread
http://www.eoeandroid.com/thread-305650-1-1.html?_dsign=047adc30