【问题标题】:Does Android support thread?安卓支持线程吗?
【发布时间】:2012-06-18 09:08:54
【问题描述】:

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;
    }
}

【问题讨论】:

  • 是否需要使用-lpthread?仅包含“pthread.h”还不够吗?

标签: android multithreading gcc android-ndk


【解决方案1】:

据我在文档中看到的,您不需要使用“-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 组...
  • 也检查一下这个:groups.google.com/d/topic/android-platform/Cq05PaLaZbE/…。一般来说,仿生包含许多 pthread 函数,但不是全部(例如,缺少 pthread_barrier_wait())。
猜你喜欢
  • 2019-04-26
  • 2022-11-18
  • 1970-01-01
  • 2014-05-30
  • 1970-01-01
  • 2013-03-25
  • 1970-01-01
  • 2010-10-22
相关资源
最近更新 更多