如何在Windows和Linux下获取当前线程的ID号
答案:1 悬赏:20
解决时间 2021-03-13 07:03
- 提问者网友:枫涩帘淞幕雨
- 2021-03-12 09:53
如何在Windows和Linux下获取当前线程的ID号
最佳答案
- 二级知识专家网友:野性且迷人
- 2021-03-12 10:42
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;
unsigned int x;
} ptw32_handle_t;
typedef ptw32_handle_t pthread_t;
与Linux的thread_t不一样,它是一个结构,不是一个整数值
在Windows和Linux下可用的获取线程ID号的内联函数如下:
#ifdef WIN32
#include <windows.h>
#else
#include <pthread.h>
#endif
inline unsigned int PthreadSelf()
{
#ifdef WIN32
return::GetCurrentThreadId();
#else
returnthread_self();
#endif
}
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;
unsigned int x;
} ptw32_handle_t;
typedef ptw32_handle_t pthread_t;
与Linux的thread_t不一样,它是一个结构,不是一个整数值
在Windows和Linux下可用的获取线程ID号的内联函数如下:
#ifdef WIN32
#include <windows.h>
#else
#include <pthread.h>
#endif
inline unsigned int PthreadSelf()
{
#ifdef WIN32
return::GetCurrentThreadId();
#else
returnthread_self();
#endif
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯