当前位置:网站首页>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
边栏推荐
- [code analysis (2)] communication efficient learning of deep networks from decentralized data
- cnpm的诡异bug
- Business case | how to promote the activity of sports and health app users? It is enough to do these points well
- 容差分析相关的计算公式
- Strange bug of cnpm
- json反序列化匿名数组/对象
- Problems encountered in the project (V) understanding of operating excel interface poi
- Function executes only the once function for the first time
- Spark入门基本操作
- UNIX final exam summary -- for direct Department
猜你喜欢
随机推荐
Jiannanchun understood the word game
读了一篇博客,重新理解闭包整理一下
接口文档yaml
JS brain burning interview question reward
第一章 电商秒杀商品回顾
Decimal 格式化小数位/DateTime 转换处理
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
Haruki Murakami -- Excerpt from "what do I talk about when I talk about running"
趣谈网络协议
Android interview theme collection
Postman reference summary
Express ② (routage)
JS 烧脑面试题大赏
JS force deduction brush question 103 Zigzag sequence traversal of binary tree
Introduction to spark basic operation
AtCoder Beginner Contest 248C Dice Sum (生成函数)
freeCodeCamp----arithmetic_ Arranger exercise
Quartus prime hardware experimental development (de2-115 board) experiment 1 CPU instruction calculator design
Tensorflow Download
JS force deduction brush question 102 Sequence traversal of binary tree







