【发布时间】:2016-02-25 16:40:50
【问题描述】:
为什么我的线程退出时我的 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::AttachCurrentThread或JavaVM::DetachCurrentThread
我不确定该做什么或寻找什么。
【问题讨论】:
-
看这个链接stackoverflow.com/questions/26534304/…。您的 logcat 匹配源中的错误消息,以便在分离之前退出线程。抱歉,如果这没有帮助。
标签: android c++ multithreading stl android-ndk