加入收藏 | 设为首页 | 会员中心 | 我要投稿 财气旺网 - 财气网 (https://www.caiqiwang.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

如何在Windows 和Linux下获取当前线程的ID号

发布时间:2022-11-21 13:00:31 所属栏目:Linux 来源:
导读:  Linux下获取当前线程ID号函数:

  pthread_t pthread_self();

  返回:当前线程的ID号

  pthread_t 数据类型的定义如下:

  typedef unsigned long int pthread_t;

  sizeof(pthr
  Linux下获取当前线程ID号函数:
 
  pthread_t pthread_self();
 
  返回:当前线程的ID号
 
  pthread_t 数据类型的定义如下:
 
  typedef unsigned long int pthread_t;
 
  sizeof(pthread_t) = 4,4个字节的整数。
 
  Windows下获取当前线程ID号的函数:
 
  DWORD GetCurrentThreadId();
 
  返回值:当前线程的ID号
 
  DWORD数据类型定义:
 
  typedef unsigned long DWORD;
 
  在Windows下pthread-win库的pthread_t定义如下:
 
  typedef struct {
 
  void * p; /*Pointer to actual object */
 
  unsigned int x; /*Extra information - reuse count etc */
 
  } ptw32_handle_t;
 
  typedef ptw32_handle_t pthread_t;
 
  与Linux的thread_t不一样线程池linux,它是一个结构,不是一个整数值
 
  在Windows和Linux下可用的获取线程ID号的内联函数如下:
 
  #ifdef WIN32
 
  #include
 
  #else
 
  #include
 
  #endif
 
  inline unsigned int PthreadSelf()
 
  {
 
  #ifdef WIN32
 
  return::GetCurrentThreadId();
 
  #else
 
  returnthread_self();
 
  #endif
 
  }
 

(编辑:财气旺网 - 财气网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!