
而这也分成两种情况:
1. 如果是pthread,则使用,
#include <pthread.h>
pthread_t pthread_self(void)
2. 如果不是pthread,即是由内核创建的线程,则使用,
#include <sys/types.h>
pid_t gettid(void)
获取线程所在的进程的id,方法如下:
#include <sys/types.h>
Linux下获取当前线程ID号函数:pthread_tpthread_self()返回:当前线程的ID号pthread_t数据类型的定义如下:typedefunsignedlongintpthread_tsizeof(pthread_t)=4,4个字节的整数。Windows下获取当前线程ID号的函数:DWORDGetCurrentThreadId()返回值:当前线程的ID号DWORD数据类型定义:typedefunsignedlongDWORD在Windows下pthread-win库的pthread_t定义如下:欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)