2016-02-25 148 views
1

为什么我的Android应用程序在我的线程退出时崩溃?当我的线程退出时,为什么我的Android应用程序崩溃?

logcat当我的应用程序崩溃时,我看到以下输出。

D/dalvikvm: threadid=13: thread exiting, not yet detached (count=0) 
D/dalvikvm: threadid=13: thread exiting, not yet detached (count=1) 
E/dalvikvm: threadid=13: native thread exited without detaching 
E/dalvikvm: VM aborting 

我不确定是什么线程导致这种情况。该应用程序使用带有少数STL线程实例的C++库(std::thread)。下面是如何我线程库工作的一个例子:

std::thread thread([context]() { ... }); 
thread.detach(); 

库工程没有在iOS,OS X和Linux的任何此类错误。我的猜测是错误不是因为缺少对std::thread::detach的呼叫。

不知道这是相关的:

  • 我用gnustl_static
  • 库通过NDK集成,但低级别的代码是平台无关的,所以我不打电话JavaVM::AttachCurrentThreadJavaVM::DetachCurrentThread

我不知道该做什么或寻找什么。

+1

看着这个链接http://stackoverflow.com/questions/26534304/android-jni-call-attachcurrentthread-without-detachcurrentthread。您的logcat与分离前退出的线程的源代码中的错误消息相匹配。对不起,如果这没有帮助。 –

回答

2

那么,东西打电话AttachCurrentThread。如果什么都没有,虚拟机不会意识到线程是否退出。

任何使JNI调用的线程必须首先连接到VM。一旦连接,它必须在退出之前分离,以避免资源泄漏。

This post有更多关于这种情况的信息,而this post有一些额外的细节。

+0

Doh!你是对的。其中一个较低级别的线程间接调用了“AttachCurrentThread”。非常感谢! –

相关问题