From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 1/3] support: Add support_wait_for_thread_exit
Date: Thu, 19 Aug 2021 18:22:31 +0200 [thread overview]
Message-ID: <87v941z9o8.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <5c0a15c2-8447-86fe-73f2-8f27147423cc@linaro.org> (Adhemerval Zanella's message of "Thu, 19 Aug 2021 13:12:51 -0300")
* Adhemerval Zanella:
> On 17/08/2021 10:50, Florian Weimer via Libc-alpha wrote:
>> ---
>> support/support.h | 4 ++
>> support/support_wait_for_thread_exit.c | 67 ++++++++++++++++++++++++++
>
> Missing the Makefile entry for support_wait_for_thread_exit
Huh, right. I must have put that into one of the other patches. Will
reshuffle.
>> +void
>> +support_wait_for_thread_exit (void)
>> +{
>> + DIR *proc_self_task = opendir ("/proc/self/task");
>> + if (proc_self_task == NULL)
>> + /* Use a large timeout because we cannot verify that the thread
>> + has exited. */
>> + usleep (5 * 1000 * 1000);
>> + else
>> + {
>> + int count;
>> +
>> + wait_again:
>> + count = 0;
>> + rewinddir (proc_self_task);
>> + while (true)
>> + {
>> + errno = 0;
>> + struct dirent *e = readdir (proc_self_task);
>> + if (e == NULL && errno != 0)
>> + FAIL_EXIT1 ("readdir: %m");
>> + if (e == NULL)
>> + {
>> + /* Only the main thread remains. Testing may continue. */
>> + TEST_VERIFY (count >= 1);
>> + closedir (proc_self_task);
>> + return;
>> + }
>> +
>> + if (strcmp (e->d_name, ".") == 0 || strcmp (e->d_name, "..") == 0)
>> + continue;
>> +
>> + ++count;
>> + if (count > 1)
>> + {
>> + /* Small timeout to give the thread a chance to exit. */
>> + usleep (50 * 1000);
>> + goto wait_again;
>> + }
>> + }
>> + }
>> +}
>>
>
> I am not very found of interfaces that poll kernel resources using timeouts,
> but I don't think we have a better Linux interface to handle this.
I think we could use pidfd_open and poll once we have a wrapper for
pidfd_open. Not sure if it's possible to get a pollable descriptor via
/proc.
Thanks,
Florian
next prev parent reply other threads:[~2021-08-19 16:22 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-17 13:50 [PATCH 0/3] Fix ESRCH issues in pthread_cancel, pthread_kill Florian Weimer
2021-08-17 13:50 ` [PATCH 1/3] support: Add support_wait_for_thread_exit Florian Weimer
2021-08-19 16:12 ` Adhemerval Zanella
2021-08-19 16:22 ` Florian Weimer [this message]
2021-08-17 13:51 ` [PATCH 2/3] nptl: pthread_kill, pthread_cancel should fail after exit (bug 19193) Florian Weimer
2021-08-17 13:51 ` [PATCH 3/3] nptl: Fix race between pthread_kill and thread exit (bug 12889) Florian Weimer
2021-08-19 16:12 ` Adhemerval Zanella
2021-08-19 16:37 ` Florian Weimer
2021-08-19 16:49 ` Adhemerval Zanella
2021-08-20 16:24 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v941z9o8.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).