public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Libc-alpha <libc-alpha@sourceware.org>,  hpa@zytor.com
Subject: Re: RFC: pthread pid accessor (BZ# 27880)
Date: Tue, 01 Jun 2021 19:54:29 +0200	[thread overview]
Message-ID: <87sg211ne2.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <05c51906-6641-552b-d779-1a075a90d5c5@linaro.org> (Adhemerval Zanella's message of "Tue, 1 Jun 2021 14:51:18 -0300")

* Adhemerval Zanella:

> On 01/06/2021 14:36, Florian Weimer wrote:
>> * Adhemerval Zanella:
>> 
>>> I think we should return the TID while the thread is being executing
>>> either cancellation handler or c++ destructors during the unwind 
>>> phase. Once no more user defined callback are being executed we should
>>> not return the TID anymore.
>> 
>>>> Yes, I would prefer that.  Does Bionic return the TID from the
>>>> resettable TCB field, or a copy?
>>>
>>> Bionic seems to maintain a list of active threads, so it returns
>>> the active thread field directly.
>> 
>> My question was whether Bionic implements that exit behavior, or
>> something else.
>> 
>
> If I understood correctly bionic implementation will just dissociate
> the thread from the global thread list *after* it has been joined by
> pthread_join.  It basically does:
>
>   pthread_join
>     thread = find_in_global_list
>
>     old_state = THREAD_NOT_JOINED
>     while (!cas (thread->join_state, &old_state, THREAD_JOINED))
>
>     if (thread->tid != 0)
>       futex_wait (&thread_tid, 0)
>
>     remove_from_global_list (thread)
>
> And the pthread assessor is basically:
>
>   pthread_gettid
>     thread = find_in_global_list
>     return thread->tid

And thread->tid isn't the field that's auto-cleared by the kernel?  Hmm.

It's still unsafe to use the handle after the join because the address
could be reused and show up again in the global list.

Thanks,
Florian


  reply	other threads:[~2021-06-01 17:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-27 19:36 Adhemerval Zanella
2021-05-31 16:51 ` Florian Weimer
2021-06-01 14:09   ` Adhemerval Zanella
2021-06-01 14:18     ` Florian Weimer
2021-06-01 15:16       ` Adhemerval Zanella
2021-06-01 17:36         ` Florian Weimer
2021-06-01 17:51           ` Adhemerval Zanella
2021-06-01 17:54             ` Florian Weimer [this message]
2021-06-01 18:01               ` Adhemerval Zanella

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=87sg211ne2.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=hpa@zytor.com \
    --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).