Android支持线程吗?

时间:2012-06-15 09:43:22

标签: android multithreading gcc android-ndk

Android支持pthreads吗? 为什么当我使用-pthread选项时,我看到链接器错误:

i686-android-linux / bin / ld:找不到-lpthread

#include <pthread.h>
#include <cxxabi.h>
extern "C" int printf (const char *, ...);
int main()
{
  try
    {
      pthread_exit (0);
    }
  catch (abi::__forced_unwind &)
    {
      printf ("caught forced unwind\n");
      throw;
    }
  catch (...)
    {
      printf ("caught ...\n");
      return 1;
    }
}

1 个答案:

答案 0 :(得分:7)

据我所知,您不需要使用“-pthread”。结帐如下:
http://mobilepearls.com/labs/native-android-api/#pthreads

来自NDK官方文档状态的信息(android-ndk-r8 \ docs \ system \ libc \ OVERVIEW.html):

PThread implementation:
Bionic's C library comes with its own pthread implementation bundled in. This is different from other historical C libraries which: - place it in an external library (-lpthread) - play linker tricks with weak symbols at dynamic link time

所以请记住,Bionic包含直接pthread而不是您习惯的标准方式(使用-lpthread)。