when is the system call set_tid_address used?
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 l开发者_开发技巧ike uptime, top etc i dont see set_tid_address being used. Why is that?
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
?
精彩评论