【问题标题】:Datatype of pthread_t in pthreads?pthreads中pthread_t的数据类型?
【发布时间】:2015-03-30 09:55:45
【问题描述】:

我有一个 32 位代码,其中使用 int 代替 pthread_t ? 所以在移植时我需要在 LP64(64 位)中更改为 long。 pthread_t 的数据类型是什么?

【问题讨论】:

  • pthread_t 类型是不透明类型,你不应该知道它到底是什么。
  • 我曾经遇到过一个 PThread 实现,其中pthread_t 被定义为一个指针。

标签: c pthreads 64-bit


【解决方案1】:

pthread_t 是实现定义的类型;不应对其基础类型进行任何假设。

POSIX.1-2008 补充说:

应用 IEEE Std 1003.1-2001/Cor 2-2004,项目 XBD/TC2/D6/26,将 pthread_t 添加到不需要为算术类型的类型列表中,从而允许将 pthread_t 定义为结构.

【讨论】:

    【解决方案2】:

    像你应该使用的那样使用pthread_t。完成。

    【讨论】:

      【解决方案3】:

      "pthread_t 的数据类型是什么?"

      x86_64-linux-gnu/bits/pthreadtypes.h:27中的定义是

      typedef unsigned long int pthread_t;
      

      其他实现可能不同。

      正如其他人所说,它被归类为不透明值。你应该这样对待它。

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多