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

2025-05-09 18:39:56
推荐回答(1个)
回答1:

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定义如下: