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

为什么我的Android应用程序在线程退出时崩溃?,android,c++,multithreading,stl,android-ndk,Android,C++,Multithreading,Stl,Android Ndk,为什么我的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 detachi

为什么我的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
我不确定是什么线程导致了这种情况。应用程序使用了一个C++库,其中有几个STL线程实例(<代码> STD::线程< /代码>)。以下是我如何在库中使用线程的示例:

std::thread thread([context] () { ... });
thread.detach();
该库在iOS、OSX和Linux上运行时不会出现任何此类错误。我的猜测是,错误不是因为缺少对
std::thread::detach
的调用

不确定是否相关:

  • 我使用
    gnustl\u static
  • 该库是通过NDK集成的,但底层代码是独立于平台的,因此我不会调用
    JavaVM::AttachCurrentThread
    JavaVM::DetachCurrentThread
我不知道该做什么或寻找什么。

嗯,有东西在调用
AttachCurrentThread
。如果什么都没有,虚拟机就不会知道线程是否退出

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


提供了有关情况的更多信息,并提供了一些其他详细信息。

查看此链接。您的logcat与源代码中的错误消息相匹配,以确定在分离之前退出的线程。如果这没用的话,我很抱歉!你是对的。其中一个较低级别的线程称为
AttachCurrentThread
。谢谢!