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.129.124]) by sourceware.org (Postfix) with ESMTPS id 0E4693858CD1 for ; Thu, 11 Jan 2024 21:32:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E4693858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0E4693858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705008751; cv=none; b=bxB6U1sLea/HlE4Pv3MTdq3zqATuM3geb0MjlWhn1vc+uaGN3v13h8rrDp/e1hJNqUcv5iz+jMoInB+zD5PIJlWoeEtxNj7mPEdYiE5OMlTE0XlUUsBYt4JaNAJZGXzVffM2ccqezswVvRENbYVtmlZCbj5WnAt52wMsGqMDHsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705008751; c=relaxed/simple; bh=CpRxebXqVCoec3KDNA2YqOKu8s0h4mxJXprXss+/rG8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dIR92OfCzXjVarvA5eJmif5HDmwFg9rFjtc83LZPDu9sFG1SuNRcDTmxJ+vw5Rk4SY/FUvzGd89J9qxH2ngxhynjYWe8M+y25jUg/EUjGrdTQPPIvp+7pTzzJl+yxExTitPiYtHhCvlRURhITEDa5+HzziL/stQoh2wFTHkZ9EI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705008749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Ru0TAtScSjv2StCP1R3RGQcAA1RgClOQUx5ReCO/JOQ=; b=FLCTh96Qzriqzst2/mQ8psJNsab6E/S6VD6eiyELA4V2JfBZ7kKqrmqXPv2Os4T5R76Emz vRUX58tcUhJ2givRz3rj4IjrzD3+GBbEyee9gcHOB7Px8ODNkBSnYJsKe1dh9yxPpX5pkx Kgkp28gJ2sOtApA7zHVTcVsLz4TfRfk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-t87cSNrwOtuYTInAeLWKwg-1; Thu, 11 Jan 2024 16:32:28 -0500 X-MC-Unique: t87cSNrwOtuYTInAeLWKwg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C9D9D85A589; Thu, 11 Jan 2024 21:32:27 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.86]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C035151D5; Thu, 11 Jan 2024 21:32:26 +0000 (UTC) From: Florian Weimer To: Trevor Gross via Libc-help Cc: Trevor Gross , jistone@redhat.com Subject: Re: RFC: A way to get a TID from a pthread_t handler References: Date: Thu, 11 Jan 2024 22:32:25 +0100 In-Reply-To: (Trevor Gross via Libc-help's message of "Thu, 11 Jan 2024 01:10:18 -0500") Message-ID: <87a5pbv9na.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: * Trevor Gross via Libc-help: > It seems like there isn't a good way to get the thread ID from a > pthread_t. If you are within the thread then you can call gettid(), > but there is no public API to get a spawned thread's TID after calling > pthread_create(). > > This value is stored in the pthread, so a new public function could > just be a basic getter: > > pid_t pthread_gettid(pthread_t threadid) > { > struct pthread *pd = (struct pthread *) threadid; > return pd->tid; > } > > Would an addition like this likely get accepted? Or is there anything > overlooked about an easier way to recover the spawned thread's TID? We should probably make a copy of the TID inside pthread_create and return that from pthread_gettid, instead of pd->tid that might be cleared by the kernel upon thread exit. This way, pthread_gettid remains valid until pthread_join is called. Thanks, Florian