当前位置:网站首页>pthread_self()为何重复了
pthread_self()为何重复了
2022-04-23 14:01:00 【JokerYourMemory】
先说结论:
由pthread_self()查的tid,只在所在进程中唯一,不同的进程可能查到相同的tid。
起因:
写了一个小程序,程序会一个以一个主进程fork出两个子进程,之后主进程投入睡眠,两个子进程各开启两个线程之后,同样投入睡眠。
一共四个线程了,日志观察时发现,对于两个子进程来说,他们pthread_create出的线程,在线程中调用pthread_self()打印线程id,竟然有两个一样,然后意识到可能不是全局唯一的。查了查,有人之前解释如下:
解释:
“pthread_self 是posix描述的线程ID(并非内核真正的线程id),相对于进程中各个线程之间的标识号,对于这个进程内是唯一的,而不同进程中,每个线程的 pthread_self() 可能返回是一样的。
而 gettid 获取的才是内核中线程ID”
引用自:https://blog.csdn.net/weixin_43204126/article/details/98236147
版权声明
本文为[JokerYourMemory]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_38084180/article/details/117451180
边栏推荐
- Introduction to spark basic operation
- scikit-learn构建模型的万能模板
- 容差分析相关的计算公式
- Analysis and understanding of atomicintegerarray source code
- 腾讯根据ip解析地址
- Lin Lin, product manager of Lenovo: network failure of local network operator in Tianjin. The background server of Zui system can't work normally for the time being
- centOS下mysql主从配置
- CentOS mysql多实例部署
- UML Unified Modeling Language
- 生产环境——
猜你喜欢
随机推荐
生产环境——
Introduction to spark basic operation
SQL learning window function
L2-024 部落 (25 分)
How does redis solve the problems of cache avalanche, cache breakdown and cache penetration
Atcoder beginer contest 248c dice sum (generating function)
China creates vast research infrastructure to support ambitious climate goals
linux MySQL数据定时dump
Quartus Prime硬件实验开发(DE2-115板)实验一CPU指令运算器设计
scikit-learn構建模型的萬能模板
Problems encountered in the project (V) understanding of operating excel interface poi
Nodejs安装及环境配置
Spark入门基本操作
美联储数字货币最新进展
Force deduction brush question 101 Symmetric binary tree
力扣刷题 101. 对称二叉树
Postman reference summary
AttributeError: ‘dict‘ object has no attribute ‘iteritems‘
关于stream流,浅记一下------
Modify the Jupiter notebook style


![Special test 05 · double integral [Li Yanfang's whole class]](/img/af/0d52a6268166812425296c3aeb8f85.png)






