当前位置:网站首页>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
边栏推荐
- AtCoder Beginner Contest 248C Dice Sum (生成函数)
- Choreographer全解析
- mysql通过binlog文件恢复数据
- FDFS start
- SQL数据库
- The art of automation
- JS 力扣刷题 103. 二叉树的锯齿形层序遍历
- 3300万IOPS、39微秒延迟、碳足迹认证,谁在认真搞事情?
- Problems encountered in the project (V) understanding of operating excel interface poi
- freeCodeCamp----arithmetic_ Arranger exercise
猜你喜欢
Express中间件③(自定义中间件)
linux安装mysql后修改密码
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
Question bank and answer analysis of the 2022 simulated examination of the latest eight members of Jiangxi construction (quality control)
go 语言 数组,字符串,切片
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
1256: bouquet for algenon
freeCodeCamp----time_ Calculator exercise
JS 烧脑面试题大赏
The art of automation
随机推荐
Modify the Jupiter notebook style
Express ② (routage)
[code analysis (7)] communication efficient learning of deep networks from decentralized data
Un modèle universel pour la construction d'un modèle d'apprentissage scikit
PATH环境变量
JS force deduction brush question 103 Zigzag sequence traversal of binary tree
China creates vast research infrastructure to support ambitious climate goals
Record a strange bug: component copy after cache component jump
VsCode-Go
关于stream流,浅记一下------
mysql通过binlog文件恢复数据
scikit-learn構建模型的萬能模板
容差分析相关的计算公式
CentOS mysql多实例部署
Express②(路由)
Express middleware ③ (custom Middleware)
Problems encountered in the project (V) understanding of operating excel interface poi
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
村上春树 --《当我谈跑步时,我谈些什么》句子摘录
The latest development of fed digital currency