public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: Florian Weimer <fweimer@redhat.com>,
	Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 3/3] nptl: Fix race between pthread_kill and thread exit (bug 12889)
Date: Thu, 19 Aug 2021 13:49:30 -0300	[thread overview]
Message-ID: <84b846a9-5304-3bca-bfc4-f1d15c26204f@linaro.org> (raw)
In-Reply-To: <87r1epz8ym.fsf@oldenburg.str.redhat.com>



On 19/08/2021 13:37, Florian Weimer wrote:
> * Adhemerval Zanella via Libc-alpha:
> 
>> On 17/08/2021 10:51, Florian Weimer via Libc-alpha wrote:
>>> Thread exit is delayed until all pending pthread_kill operations
>>> on the thread have completed.  This avoids sending signals to the
>>> wrong thread or a spurious ESRCH error.
>>>
>>> The test sysdeps/pthread/tst-pthread_cancel-select-loop.c is derived
>>> from a downstream test originally written by Marek Polacek.
>>
>> And I really hope we could first sort out the BZ#19951 and move away
>> of using pthread::tid as the synchronization member to check thread
>> termination.  I sent a possible fix [1], but it does not fully handle
>> the pthread::tid access, it would require to a proper lock to 
>> synchronize between thread exit and pthread_kill (as Rich has suggested
>> on BZ#12889).
>>
>> I will need to send an updated version of my pthread fixes patchset,
>> since clone3 changes broke it and INVALID_TD_P needs fixing as well.
>>
>> [1] https://patchwork.sourceware.org/project/glibc/patch/20210610193639.3650754-5-adhemerval.zanella@linaro.org/
> 
> I think my patch is independent of the other fixes.  Its advantage over
> other proposals is that it does not add waiting to pthread_kill, so
> there is no signal-safety issue.

I am not sure, the way I think we should fix to also fix BZ#19951
would to add a lock to access 'tid' and uses not only on pthread_kill,
but also on pthread_getcpuclockid, pthread_getschedparam, 
pthread_setschedparam, and pthread_setschedprio.  The lock also
simplifies the code, there is no need to special handling of futex
internal state. I also think pthread_kill would also be simplified.

The lock is just to simplify the code, if we really need to add
some scalability we might use a more clever code as you are proposing.

> 
> (But I probably should test if cancellation from a signal handler that
> is invoked synchronously via pthread_kill still works.)
> 
> Thanks,
> Florian
> 

  reply	other threads:[~2021-08-19 16:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 13:50 [PATCH 0/3] Fix ESRCH issues in pthread_cancel, pthread_kill Florian Weimer
2021-08-17 13:50 ` [PATCH 1/3] support: Add support_wait_for_thread_exit Florian Weimer
2021-08-19 16:12   ` Adhemerval Zanella
2021-08-19 16:22     ` Florian Weimer
2021-08-17 13:51 ` [PATCH 2/3] nptl: pthread_kill, pthread_cancel should fail after exit (bug 19193) Florian Weimer
2021-08-17 13:51 ` [PATCH 3/3] nptl: Fix race between pthread_kill and thread exit (bug 12889) Florian Weimer
2021-08-19 16:12   ` Adhemerval Zanella
2021-08-19 16:37     ` Florian Weimer
2021-08-19 16:49       ` Adhemerval Zanella [this message]
2021-08-20 16:24         ` Florian Weimer

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=84b846a9-5304-3bca-bfc4-f1d15c26204f@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.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).