简体   繁体   English

如果未在pthread_create上将其作为参数传递,是否可以从C / C ++的线程中获取父线程ID?

[英]Is it possible from within a thread in C/C++ to get a parent thread id if it wasn't passed in as an argument on pthread_create?

pthread_self() is to get your own thread id. pthread_self()是要获取自己的线程ID。 It doesn't seem like you can get the thread id of the thread which spawned you unless it was given to you during spawning. 除非您在生成时将其提供给您,否则似乎无法获得生成您的线程的线程ID。 Or is there a way? 还是有办法?

No, all threads are equal in POSIX threads, there is no hierarchy. 不,所有线程在POSIX线程中都是相等的,没有层次结构。 Even the thread that executes main has no special role and can be terminated without effecting the others. 即使执行main的线程也没有特殊作用,并且可以终止而不会影响其他线程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM