安卓系统支持线程吗?

4
Android是否支持pthread? 为什么当我使用-pthread选项时,会看到链接器错误: i686-android-linux/bin/ld: cannot find -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;
    }
}

你需要使用-lpthread吗?仅包含“pthread.h”是否就足够了? - Bo.
1个回答

7
据我所看到的文档,你不需要使用“-pthread”。请查看以下内容:http://mobilepearls.com/labs/native-android-api/#pthreads 来自NDK官方文档的信息(android-ndk-r8\docs\system\libc\OVERVIEW.html):
PThread实现: Bionic的C库内置了自己的pthread实现。 这与其他历史悠久的C库不同,它们: - 将其放在外部库中(-lpthread) - 在动态链接时使用弱符号进行链接器技巧
因此,请记住,Bionic直接包含pthread,而不是您通常使用的标准方式(使用-lpthread)。

我能相信这个链接吗?因为它不是developer.android.com或他们的Google群组... - Laser
1
请查看此链接:https://groups.google.com/d/topic/android-platform/Cq05PaLaZbE/discussion。总的来说,Bionic 包含许多 pthread 函数,但并非全部(例如,缺少 pthread_barrier_wait())。 - gfour

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接