<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Jun 16, 2019 at 5:52 PM Jan Stancek <<a href="mailto:jstancek@redhat.com">jstancek@redhat.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Case where defunct tid is used has been observed to sporadically fail:<br>
  tgkill03.c:96: FAIL: Defunct tid should have failed with ESRCH: SUCCESS<br>
<br>
glibc __pthread_timedjoin_ex() waits for CLONE_CHILD_CLEARTID to clear tid,<br>
and then resumes. Kernel clears it (glibc pd->tid) at:<br>
  do_exit<br>
    exit_mm<br>
      mm_release<br>
        put_user(0, tsk->clear_child_tid);<br>
<br>
but kernel tid is still valid, presumably until:<br>
  release_task<br>
    __exit_signal<br>
      __unhash_process<br>
        detach_pid<br>
<br>
To avoid race wait until /proc/<pid>/task/<tid> disappears.<br>
<br>
Signed-off-by: Jan Stancek <<a href="mailto:jstancek@redhat.com" target="_blank">jstancek@redhat.com</a>><br>
---<br>
 testcases/kernel/syscalls/tgkill/tgkill03.c | 6 +++++-<br>
 1 file changed, 5 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/testcases/kernel/syscalls/tgkill/tgkill03.c b/testcases/kernel/syscalls/tgkill/tgkill03.c<br>
index f5bbdc5a8d4e..5ac1d2651f7a 100644<br>
--- a/testcases/kernel/syscalls/tgkill/tgkill03.c<br>
+++ b/testcases/kernel/syscalls/tgkill/tgkill03.c<br>
@@ -7,6 +7,7 @@<br>
<br>
 #include <pthread.h><br>
 #include <pwd.h><br>
+#include <stdio.h><br>
 #include <sys/types.h><br>
<br>
 #include "tst_safe_pthread.h"<br>
@@ -42,6 +43,7 @@ static void setup(void)<br>
 {<br>
        sigset_t sigusr1;<br>
        pthread_t defunct_thread;<br>
+       char defunct_tid_path[PATH_MAX];<br>
<br>
        sigemptyset(&sigusr1);<br>
        sigaddset(&sigusr1, SIGUSR1);<br>
@@ -55,8 +57,10 @@ static void setup(void)<br>
        TST_CHECKPOINT_WAIT(0);<br>
<br>
        SAFE_PTHREAD_CREATE(&defunct_thread, NULL, defunct_thread_func, NULL);<br>
-<br>
        SAFE_PTHREAD_JOIN(defunct_thread, NULL);<br>
+       sprintf(defunct_tid_path, "/proc/%d/task/%d", getpid(), defunct_tid);<br>
+       while (access(defunct_tid_path, R_OK) == 0)<br>
+               usleep(10000);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">To be on the safe side, I think maybe TST_RETRY_FUNC is a better choice here.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">    TST_RETRY_FUNC(access(defunct_tid_path, R_OK), -1);</div></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
 }<br>
<br>
 static void cleanup(void)<br>
-- <br>
1.8.3.1<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr">Regards,<br>Li Wang<br></div></div></div></div></div>