当前位置:网站首页>pthread_ Why does self() repeat

pthread_ Why does self() repeat

2022-04-23 14:06:00 JokerYourMemory

Say first conclusion :

from pthread_self() Checked tid, Only unique in the process , Different processes may find the same tid.

cause :

Wrote a little program , The program will run as a main process fork There are two sub processes , Then the main process goes to sleep , After two sub processes are started , Also sleep .

There are four threads in total , During log observation, it is found that , For two subprocesses , they pthread_create Outgoing thread , It is called in the thread pthread_self() Print thread id, There are two of them , Then realize that it may not be the only one . Check it out , Someone explained earlier as follows :

explain :

“pthread_self yes posix Thread described ID( Not a real thread in the kernel id), Relative to the identification number of each process in the thread , For this process is the only , And in different processes , Per thread pthread_self() Maybe the return is the same .
and gettid What you get is the thread in the kernel ID”

Quote from :https://blog.csdn.net/weixin_43204126/article/details/98236147

版权声明
本文为[JokerYourMemory]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401090664.html