// pthread_self 函数
#include<pthread.h>
pthread_t pthread_self();
/*
每个线程也有一个线程号,进程号在整个系统中是惟一的,但线程号不同,线程与只有在它所属的
进程环境中有效,进程号用 pid_t 数据类型表示,是一个非负数,线程号则用 pthread_t 数据类型来表示,
Linux 使用无符号长整数表示,有的系统实现的时候,是用结构体,所以在可移植的操作系统实现上不能将其
作为整数处理
功能 获取线程号
参数 无
返回 线程ID
*/
// pthread_equal 函数
#include<pthread.h>
int pthread_equal(pthread_t t1,pthread_t t2);
/*
功能 判断线程号 t1 和 t2 是否相等
参数 t1,t2 待判断的线程号
返回 相等 非0 不相等 0
*/
// pthread1.c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<pthread.h>
int main(){
pthread_t tid=0;
tid=pthread_self();
printf("tid %lun",tid);
if(pthread_equal(tid,pthread_self())){
printf("yesn");
}else{
printf("non");
}
return 0;
}
// 编译 gcc pthread1.c -pthread -o pthread1
// 运行 ./pthread1 结果如下
//
![fbffa7795816345b105a6acdf7bf13d9.png](https://i-blog.csdnimg.cn/blog_migrate/ae6b472db075c10d072b0d03fc5d621c.jpeg)