Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ndk pthread_getspecific后Android应用程序JNI/Java崩溃_Android Ndk_Java Native Interface - Fatal编程技术网

Android ndk pthread_getspecific后Android应用程序JNI/Java崩溃

Android ndk pthread_getspecific后Android应用程序JNI/Java崩溃,android-ndk,java-native-interface,Android Ndk,Java Native Interface,我有一个很奇怪的问题 我的应用程序在JNI C代码部分的pthread_getspecific之后崩溃,但奇怪的是,这是因为它没有直接崩溃,因为在崩溃之前我多次使用这个函数,一切都很好 因此,这里是崩溃发生的C代码: int *compteur; __android_log_print(ANDROID_LOG_INFO, "JNI", "before getspecific key : %d",key); compteur=(int*)pthread_getspecific(key); __an

我有一个很奇怪的问题

我的应用程序在JNI C代码部分的pthread_getspecific之后崩溃,但奇怪的是,这是因为它没有直接崩溃,因为在崩溃之前我多次使用这个函数,一切都很好

因此,这里是崩溃发生的C代码:

int *compteur;
__android_log_print(ANDROID_LOG_INFO, "JNI", "before getspecific key : %d",key);
compteur=(int*)pthread_getspecific(key);
__android_log_print(ANDROID_LOG_ERROR, "JNI", "error %s",strerror(errno));
__android_log_print(ANDROID_LOG_INFO, "JNI", "pointeur : %ld",*compteur);
(*compteur)=(*compteur)-1;
if ((*compteur)==0)
{
  pthread_mutex_unlock(&mutex));
}  
logcat告诉我:

>     before getspecific key : 13
>     error Unknown error: 0
>     pointeur : 1
>     before getspecific key : 13
>     error Unknown error: 0
>     pointeur : 1
>     before getspecific key : 13
>     error Unknown error: 0
CRASH
因此,对于ndk堆栈,我有:

$home>adb logcat | ndk-stack -sym obj
/local/armeabi
********** Crash dump: **********
Build fingerprint: 'archos/G9A80/A80:3.2.1/HTK75D/20120103.181511:user/release-keys'
pid: 7322, tid: 7332  >>> com.prg.main <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
Stack frame #00  pc 00012532  /data/data/com.prg.main/lib/libPrg.so (the function where the crash appens): Routine
(the function where the crash appens) in myfile.c:75
...
Stack frame #04  pc 00011770  /system/lib/libc.so (__thread_entry)
Stack frame #05  pc 000112c4  /system/lib/libc.so (pthread_create)
Crash dump is completed

如果你有什么想法可以解决我的问题,欢迎你

你是否将标准输出设置为无缓冲,以便在崩溃前准确地获得输出?我真的不明白。。。与ndk stack相比,我们可以获得更多关于崩溃的信息?标准输出为bufferred-这意味着并非所有printf:s都像执行时一样显示。因此,当应用程序崩溃时,一些printf:s可能会出现在缓冲区中,而这些printf:s不会从缓冲区中清除。然后可能会出现崩溃发生在其他地方。但从ndk堆栈来看,崩溃发生在第75行。第75行的myfile.c是什么?哦,好的,第75行是这样的:\uuuuAndroid\uLog\uPrintAndroid\uLog\uInfo,JNI,指针:%ld,*compteur;问题已经解决了,事实上它不在这里。。。我没有将java虚拟机连接到当前线程,现在,我的应用程序在其他地方崩溃。在我的JNI_OnLoad方法中,我使用AttachCurrentThread将vm附加到当前线程,然后将findClass结果存储在声明为jclass myClass的变量中;在我的头文件中。但是当我试图从我的C代码中调用java方法时,它告诉我调用不是从JavaVM线程完成的。谢谢你@Jakub Zaverka