什么时候使用系统调用set_tid_address? [英] when is the system call set_tid_address used?
问题描述
我一直试图理解系统调用,并想了解set_tid_address的工作方式.从我所读到的内容来看,基本上是它返回执行的程序或进程的pid.
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.
我已经用ls进行了测试,但是使用了诸如正常运行时间,top等命令,我看不到使用了set_tid_address.为什么会这样?
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?
推荐答案
clone()
系统调用可以使用 CLONE_CHILD_CLEARTID
标志,该标志位于 child_tidptr
(另一个 clone()
参数)被清除,并且相关联的futex在子线程退出时发出唤醒信号.这用于实现 pthread_join()
(父线程在futex上等待).
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()
允许在初始线程上 pthread_join()
.以下LKML线程中的更多信息:
set_tid_address()
allows to pthread_join()
on the initial thread. More information in the following LKML threads:
[补丁]线程修复,tid-2.5.47-A3
[补丁] user-vm-unlock-2.5.31-A2
关于为什么某些程序调用 set_tid_address()
而其他程序不调用的原因,答案很简单.(直接或间接)链接到libpthread的程序调用 set_tid_address
. ls
链接到 librt
,后者链接到 libpthread
,因此它运行NPTL的初始化.
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.
这篇关于什么时候使用系统调用set_tid_address?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!