From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7491C43331 for ; Tue, 12 Nov 2019 22:11:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C3A2B21783 for ; Tue, 12 Nov 2019 22:11:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726960AbfKLWLP (ORCPT ); Tue, 12 Nov 2019 17:11:15 -0500 Received: from albireo.enyo.de ([37.24.231.21]:38062 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726896AbfKLWLP (ORCPT ); Tue, 12 Nov 2019 17:11:15 -0500 Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1iUeNT-0001HG-JC; Tue, 12 Nov 2019 22:11:11 +0000 Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1iUeNT-000728-HI; Tue, 12 Nov 2019 23:11:11 +0100 From: Florian Weimer To: enh Cc: "Michael Kerrisk \(man-pages\)" , linux-man@vger.kernel.org Subject: Re: [PATCH] pthread_kill.3: Update to match POSIX. References: <87imnodbct.fsf@mid.deneb.enyo.de> <877e44daom.fsf@mid.deneb.enyo.de> Date: Tue, 12 Nov 2019 23:11:11 +0100 In-Reply-To: (enh's message of "Tue, 12 Nov 2019 14:06:05 -0800") Message-ID: <87woc4bv9c.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-man-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-man@vger.kernel.org * enh: > On Tue, Nov 12, 2019 at 1:52 PM Florian Weimer wrote: >> >> * enh: >> >> > On Tue, Nov 12, 2019 at 1:38 PM Florian Weimer wrote: >> >> >> >> * enh: >> >> >> >> > POSIX removed ESRCH years ago. >> >> > >> >> > In resolving http://austingroupbugs.net/view.php?id=1214 it was made >> >> > clear that callers can't rely on using signal 0 to test for the >> >> > continued existence of a thread. Update the man page to make it clearer >> >> > that this doesn't generally work (even if it sometimes seems to). >> >> > >> >> > See also the long explanation of why this is the case (and how to fix >> >> > your code) here: >> >> > >> >> > https://android.googlesource.com/platform/bionic/+/master/docs/status.md#invalid-handling-targetsdkversion-o >> >> >> >> Well, if you fix the thread exit race (like musl did, and glibc should >> >> as well, see bug 12889), you could get a reliable ESRCH as a side >> >> effect. Pity that POSIX doesn't allow that. >> > >> > this isn't about the tid stored *in* the object that the pthread_t >> > points to. >> > >> > like i (briefly) said in the commit message, this is because a >> > pthread_t is a pointer, so if you have an old pthread_t that's been >> > recycled... boom! >> >> Backing storage for a pthread_t object denoting a joinable thread >> cannot be recycled, so that's not the case here. POSIX mandates >> returning success even if the implementation has detected that it must >> not send the signal because the thread has already terminated. > > who said anything about joinable? That determines whether the pthread_t object is still valid. > the cases we've seen in practice are that folks incorrectly believe > that pthread_kill(3) with a signal of 0 is a reliable way to test > whether a thread is still running. Right, that's not working according to (future) POSIX. Which I dislike because a correct implementation of pthread_kill has to do all the work to support this usage (or something like it; after all, only testing for termination gives stable results), and then is forced by POSIX to discard the data.