when is the system call set_tid_address used?

泄露秘密 提交于 2019-12-06 07:54:44

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.

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?

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