when is the system call set_tid_address used?

微笑、不失礼 提交于 2019-12-10 11:32:43

问题


i have been trying to undertand the system calls, and want to understand how set_tid_address works. bascially from what i have read is that it returns the pid of the program or process which is executed.

I have tested this with ls, however with some commands like uptime, top etc i dont see set_tid_address being used. Why is that?


回答1:


The clone() syscall can take a CLONE_CHILD_CLEARTID flag, that the value at child_tidptr (another clone() argument) gets cleared and an associated futex signal a wake-up when the child thread exits. This is used to implement pthread_join() (the parent thread waits on the futex).

set_tid_address() allows to pthread_join() on the initial thread. More information in the following LKML threads:

[patch] threading fix, tid-2.5.47-A3
[patch] user-vm-unlock-2.5.31-A2

As to why some programs call set_tid_address() and others don't, the answer is easy. Programs linked (directly or indirectly) to libpthread call set_tid_address. ls is linked to librt, which is linked to libpthread, so it runs the initialization for NPTL.




回答2:


According to the Linux Programmer's Manual, set_tid_address is used to:

set pointer to thread ID

When it is finished, it returns the PID of the calling process. Unfortunately the manual is vague as to when you would actually want to use this system call.

In any case, why do you think that these commands are using set_tid_address?



来源:https://stackoverflow.com/questions/6975098/when-is-the-system-call-set-tid-address-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!