如果您使用 c++_shared(LLVM 的 libc++)链接并且您的应用程序至少使用了一次 pthread_create
,任何对 sscanf
的调用(在 pthread_create
) 将在 pthread_mutex_lock
中挂起。
最佳答案
原因是在 Google 的“android_support”辅助库中轻率地使用了“struct FILE”内部结构。很可能在 Android 5.0 Bionic 中更改了此结构。
由于 NDK r10d 消除了 android_support 的错误 sscanf
实现(在 commit 47e68e84ee043436387a053c1cd47b97cabbb8ca 中),它不再受到影响。如果您必须使用较旧的 NDK,请申请 commit 47e68e84ee043436387a053c1cd47b97cabbb8ca将其作为临时修复。
下面是简单的复制。
应用程序.mk:
APP_ABI := armeabi
APP_STL := c++_shared
APP_PIE := true
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := test.cpp
include $(BUILD_EXECUTABLE)
测试.cpp:
#include <stdio.h>
#include <pthread.h>
void* threadproc(void *) {
return NULL;
}
int main(int argc, char **argv) {
pthread_t thread;
pthread_create(&thread, NULL, threadproc, NULL); // causes __isthreaded to be set
unsigned int foo;
sscanf("12345", "%u", &foo); // locks up by calling Bionic's flockfile on its own fake FLE
}
关于android - 在 Android 5.0 (Lollipop) 上运行时使用 APP_STL=c++_shared 在 sscanf 中挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27847322/