From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 94286385E83F for ; Thu, 19 Aug 2021 16:22:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 94286385E83F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-96-2mDu_T5yM1m6HHqb5eXGew-1; Thu, 19 Aug 2021 12:22:35 -0400 X-MC-Unique: 2mDu_T5yM1m6HHqb5eXGew-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 34C6C1008060; Thu, 19 Aug 2021 16:22:34 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.194.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5B1C91970F; Thu, 19 Aug 2021 16:22:33 +0000 (UTC) From: Florian Weimer To: Adhemerval Zanella Cc: libc-alpha@sourceware.org Subject: Re: [PATCH 1/3] support: Add support_wait_for_thread_exit References: <3c76c76c7f0a25bfb9581a43693ebab13b50043d.1629208174.git.fweimer@redhat.com> <5c0a15c2-8447-86fe-73f2-8f27147423cc@linaro.org> Date: Thu, 19 Aug 2021 18:22:31 +0200 In-Reply-To: <5c0a15c2-8447-86fe-73f2-8f27147423cc@linaro.org> (Adhemerval Zanella's message of "Thu, 19 Aug 2021 13:12:51 -0300") Message-ID: <87v941z9o8.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Aug 2021 16:22:37 -0000 * 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