When going through the glibc code, a line is observed describing " Note that we do not reset the 'used' flag in the 'tid' field. This is done by the kernel" in glibc_source (version 2.21) (link to file in glibc source) at line 760.
As per my understanding glibc reuses the thread stack for T2 maintained in cache stack list. But before reusing that stack, it check for tid field in the thread descriptor of T1 (which is already reset to -1 after pthread_join of T1).
T1 - First thread.
T2 - Second thread created after T1 exited.
As per the comment in file (allocatestack.c:760), 'tid' field of struct pthread is reset by linux kernel. But, as per my understanding the tid field is reset by pthread_join.
how 'tid' field is reset by kernel ? Please correct if my understanding is wrong.