[PATCH 5/6] support: Add support_thread_state_wait

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Dec 18 17:28:51 GMT 2025



On 18/12/25 10:45, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> Same as support_process_state_wait, but wait for the task TID
>> (obtained with gettid) from the current process.  Since the kernel
>> might remove the /proc/<pid>/task/<tid>/status at any time if the
>> thread terminates, the code needs to handle possible
>> fopen/getline/fclose failures due to an inexistent file.
> 
> This does not guard against TID reuse.  I don't know how to accomplish
> that.  The 22nd field of /proc/<pid>/task/<tid>/stat is the process
> start time, not the thread creation time.

I think with Linux 6.9+ we can use PIDFD_THREAD and use waitid(P_PIDFD,...).

I am not sure is this would be a problem, it really depends of the
/proc/sys/kernel/pid_max value and the system load.  I think if we
start to see too many spurious errors we can switch to PIDFD_THREAD
instead.

> 
> Maybe just document this in the header file as a responsibility of the
> caller?

I changed to:

/* Same as support_process_state_wait, but wait for the task TID (obtained
   with gettid) from the current process.
   NB: this function does not guard against TID reuse (the kernel might
   assign the TID to a different thread between the gettid and the function
   call if the thread exits and another is created).  It is the caller's
   responsibility to ensure the call is safe to use.  */

Are you ok with this change?




More information about the Libc-alpha mailing list