public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "adhemerval.zanella at linaro dot org" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug nptl/27880] Please provide a pthread pid accessor
Date: Thu, 27 May 2021 19:32:19 +0000	[thread overview]
Message-ID: <bug-27880-131-Bp5zaDVeDU@http.sourceware.org/bugzilla/> (raw)
In-Reply-To: <bug-27880-131@http.sourceware.org/bugzilla/>

https://sourceware.org/bugzilla/show_bug.cgi?id=27880

--- Comment #10 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> ---
It seems that this is trickier than it seems, some issues we might considere
first:

  1. What should we do with detached threads? As for pthread_kill, issuing a
pthread_gettid_np might use an invalid handler (since the pthread_t identifier
might be reused).  This only solution I have is to define it as undefined
behavior, this is not great but to proper support it would incur to keep
tracking or all possible pthread_t identifiers (we already keep the glibc
provided stacks, dl_stack_cache, so it would be a matter to include the user
provided one in the list as special entries).

  2. I think that once we provide this API, developers will start to use o
query if a thread is alive and I am not sure if this is really the proper API
for this. This is the same issue as 1.

  3. How do we handle the concurrent access between pthread_join and
pthread_gettid_np? Once a pthread_join is issued, the pthread_t identifier
might be reused and accessing it should be invalid. pthread_join first
synchronizes using 'joinid' to avoid concurrent pthread_join and then wait the
kernel signal on 'tid' that the thread has finished.  The 'pthread_gettid_np'
naive check would just do a atomic load on tid, however it might read a
transient value between pthread_join 'joinid' setup and the futex wait.  I am
not sure how to handle it correctly.

Also, MacOSX signature is:

  int pthread_gettid_np (pthread_t thread, uint64_t *thread_id)

And it returns the current thread identification if THREAD is NULL, returns
ESRCH for invalid handle (the 1. and 2. issue below), and also consults the
kernel if the identifier can no be obtained.

I think for possible glibc symbols we should use a pid_t instead, the NULL
special arguments is also tricky because if by POSIX pthread_t might be NULL
(this is an implementation detail), for ESRCH we can our
INVALID_NOT_TERMINATED_TD_P (which not the best solution, but it the current
pratice).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

  parent reply	other threads:[~2021-05-27 19:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18  1:19 [Bug nptl/27880] New: " hpa at zytor dot com
2021-05-18  5:05 ` [Bug nptl/27880] " hpa at zytor dot com
2021-05-18 18:36 ` joseph at codesourcery dot com
2021-05-18 19:31 ` hpa at zytor dot com
2021-05-18 20:58 ` adhemerval.zanella at linaro dot org
2021-05-19 20:14 ` fweimer at redhat dot com
2021-05-19 20:21 ` hpa at zytor dot com
2021-05-19 20:27 ` adhemerval.zanella at linaro dot org
2021-05-19 20:31 ` hpa at zytor dot com
2021-05-19 20:49 ` fweimer at redhat dot com
2021-05-19 22:50 ` mtk.manpages at gmail dot com
2021-05-27 19:32 ` adhemerval.zanella at linaro dot org [this message]
2021-05-27 23:48 ` hpa at zytor dot com
2023-04-14  3:50 ` sam at gentoo dot org
2024-02-06 22:30 ` jkriegshauser at gmail dot com

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=bug-27880-131-Bp5zaDVeDU@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@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).