linux 内核如何重置 GLIBC "struct pthread" 中 'tid' 字段中的 'used' 标志?
How does linux kernel reset the 'used' flag in the 'tid' field in "struct pthread" of GLIBC?
在检查 glibc 代码时,观察到一行描述“请注意,我们不会在 'tid' 字段中重置 'used' 标志。这是由内核完成的” glibc_source(版本 2.21)(link to file in glibc source)在第 760 行。
根据我的理解,glibc 重用缓存堆栈列表中维护的 T2 线程堆栈。但在重用该堆栈之前,它会检查 T1 的线程描述符中的 tid 字段(在 T1 的 pthread_join 之后已重置为 -1)。
T1 - First thread.
T2 - Second thread created after T1 exited.
根据文件 (allocatestack.c:760) 中的注释,linux 内核重置了 struct pthread 的 'tid' 字段。但是,根据我的理解,tid 字段由 pthread_join 重置。
内核如何重置 'tid' 字段?理解有误请指正
这里的意思是,tid
成员也作为标志,表示栈是否在使用中。它没有引用成员内部的位。
内核在线程退出时将tid
成员设置为零,因为clone
系统调用是用CLONE_CHILD_CLEARTID
标志调用的,而[=10=的地址] 成员传递给它。有关详细信息,请参阅 sysdeps/unix/sysv/linux/createthread.c
。
在检查 glibc 代码时,观察到一行描述“请注意,我们不会在 'tid' 字段中重置 'used' 标志。这是由内核完成的” glibc_source(版本 2.21)(link to file in glibc source)在第 760 行。
根据我的理解,glibc 重用缓存堆栈列表中维护的 T2 线程堆栈。但在重用该堆栈之前,它会检查 T1 的线程描述符中的 tid 字段(在 T1 的 pthread_join 之后已重置为 -1)。
T1 - First thread.
T2 - Second thread created after T1 exited.
根据文件 (allocatestack.c:760) 中的注释,linux 内核重置了 struct pthread 的 'tid' 字段。但是,根据我的理解,tid 字段由 pthread_join 重置。
内核如何重置 'tid' 字段?理解有误请指正
这里的意思是,tid
成员也作为标志,表示栈是否在使用中。它没有引用成员内部的位。
内核在线程退出时将tid
成员设置为零,因为clone
系统调用是用CLONE_CHILD_CLEARTID
标志调用的,而[=10=的地址] 成员传递给它。有关详细信息,请参阅 sysdeps/unix/sysv/linux/createthread.c
。