From: Florian Weimer <fweimer@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH v2 06/19] nptl: Replace struct thread cancelhandling field
Date: Thu, 26 Aug 2021 16:34:46 +0200 [thread overview]
Message-ID: <87r1eg5l6h.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20210823195047.543237-7-adhemerval.zanella@linaro.org> (Adhemerval Zanella's message of "Mon, 23 Aug 2021 16:50:34 -0300")
* Adhemerval Zanella:
> Now that both thread state and setxid is being tracked by two different
> fields ('joinstate' and 'setxid_flag'), there is no need to keep track
> of exiting (EXITING_BIT) and terminated (TERMINATED_BIT) state in
> 'cancelhandling'.
>
> The 'cancelhandling' field is renamed to 'cancelstatus' and it only
> signals whether the thread has been cancelled (set by pthread_cancel()).
> It allows simplify the atomic operation required to avoid CAS
> operations.
“cancelstatus” is a bad name because “cancel state” is POSIX terminology
with different meaning. Please choose a different name.
I think pending_cancel or cancel_requested would work.
> There is no need to check the thread state on
> __pthread_enable_asynccancel() nor on pthread_testcancel () anymore,
> since cancellation is explicit disabled when thread start the exit code
> on __do_cancel().
“explict[ly]”
>
> On __nptl_free_tcp(), the 'joinstate' now defines whether it is the
“__nptl_free_tcb”.
> creating thread or the created thread that calls it. So there is
> no concurrent call within the function and thus no need to set the
> TERMINATED_BIT.
>
> For SIGCANCEL handler, sigcancel_handler(), 'joinstate' is used instead
> (pthread_cancel() might still be called concurrenty in assynchronous
> mode).
“as[]ynchronous”
> diff --git a/nptl/nptl_free_tcb.c b/nptl/nptl_free_tcb.c
> index cbf3580f59..15e1a18562 100644
> --- a/nptl/nptl_free_tcb.c
> +++ b/nptl/nptl_free_tcb.c
> @@ -24,22 +24,12 @@
> void
> __nptl_free_tcb (struct pthread *pd)
> {
> - /* The thread is exiting now. */
> - if (atomic_bit_test_set (&pd->cancelhandling, TERMINATED_BIT) == 0)
> - {
> - /* Free TPP data. */
> - if (pd->tpp != NULL)
> - {
> - struct priority_protection_data *tpp = pd->tpp;
> + free (pd->tpp);
> + pd->tpp = NULL;
For detached threads, this is called on the thread after signals have
been blocked. I don't think this is entirely correct. And things
become rather interesting if malloc needs pd->tpp.
It's not clear to me whether this could happen before.
> + /* Queue the stack memory block for reuse and exit the process. The kernel
> + will signal via writing to the address returned by QUEUE-STACK when the
> + stack is available. */
> + __nptl_deallocate_stack (pd);
> }
That old comment seems to be out-of-date.
> libc_hidden_def (__nptl_free_tcb)
> diff --git a/nptl/pthread_cancel.c b/nptl/pthread_cancel.c
> index 67e00ef007..aed6c1ea47 100644
> --- a/nptl/pthread_cancel.c
> +++ b/nptl/pthread_cancel.c
> @@ -93,8 +90,9 @@ __pthread_cancel (pthread_t th)
> }
> #endif
>
> - int oldch = atomic_fetch_or_acquire (&pd->cancelhandling, CANCELED_BITMASK);
> - if ((oldch & CANCELED_BITMASK) != 0)
> + /* If already cancelled just return (cancellation will be acted upon in next
> + cancellation entrypoint). */
> + if (atomic_exchange_acquire (&pd->cancelstatus, 1) == 1)
> return 0;
This should probably use relaxed MO.
The libthreaddb changes look okay to me.
Thanks,
Florian
next prev parent reply other threads:[~2021-08-26 14:35 UTC|newest]
Thread overview: 68+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-23 19:50 [PATCH v2 00/19] Fix various NPTL synchronization issues Adhemerval Zanella
2021-08-23 19:50 ` [PATCH v2 01/19] nptl: Fix tst-cancel7 and tst-cancelx7 race condition (BZ #14232) Adhemerval Zanella
2021-08-26 9:33 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 02/19] nptl: Set cancellation type and state on pthread_exit Adhemerval Zanella
2021-08-26 9:38 ` Florian Weimer
2021-08-26 9:42 ` Florian Weimer
2021-08-26 11:56 ` Adhemerval Zanella
2021-08-26 11:52 ` Adhemerval Zanella
2021-08-26 12:08 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 03/19] nptl: Handle robust PI mutexes for !__ASSUME_SET_ROBUST_LIST Adhemerval Zanella
2021-08-26 9:42 ` Florian Weimer
2021-08-26 12:14 ` Adhemerval Zanella
2021-08-23 19:50 ` [PATCH v2 04/19] nptl: Do not use pthread set_tid_address as state synchronization (BZ #19951) Adhemerval Zanella
2021-08-26 10:41 ` Florian Weimer
2021-08-26 14:58 ` Adhemerval Zanella
2021-08-26 15:06 ` Florian Weimer
2021-08-26 16:16 ` Adhemerval Zanella
2021-08-30 10:42 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 05/19] nptl: Move setxid flag out of cancelhandling Adhemerval Zanella
2021-08-26 11:34 ` Florian Weimer
2021-08-26 15:11 ` Adhemerval Zanella
2021-08-26 15:21 ` Florian Weimer
2021-08-26 16:39 ` Adhemerval Zanella
2021-08-30 11:27 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 06/19] nptl: Replace struct thread cancelhandling field Adhemerval Zanella
2021-08-26 14:34 ` Florian Weimer [this message]
2021-08-26 16:48 ` Adhemerval Zanella
2021-08-30 10:36 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 07/19] support: Add support_wait_for_thread_exit Adhemerval Zanella
2021-08-26 9:31 ` Florian Weimer
2021-08-26 16:49 ` Adhemerval Zanella
2021-08-30 11:46 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 08/19] nptl: pthread_kill, pthread_cancel should fail after exit (bug 19193) Adhemerval Zanella
2021-08-26 10:03 ` Florian Weimer
2021-08-26 16:49 ` Adhemerval Zanella
2021-08-23 19:50 ` [PATCH v2 09/19] nptl: Fix race between pthread_kill and thread exit (bug 12889) Adhemerval Zanella
2021-08-26 14:23 ` Florian Weimer
2021-08-26 17:06 ` Adhemerval Zanella
2021-08-30 9:25 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 10/19] nptl: Use tidlock when accessing TID on pthread_getaffinity_np Adhemerval Zanella
2021-08-26 14:24 ` Florian Weimer
2021-08-26 17:29 ` Adhemerval Zanella
2021-08-30 9:30 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 11/19] nptl: Use tidlock when accessing TID on pthread_setaffinity Adhemerval Zanella
2021-08-26 14:25 ` Florian Weimer
2021-08-26 17:31 ` Adhemerval Zanella
2021-08-23 19:50 ` [PATCH v2 12/19] nptl: Use tidlock when accessing TID on pthread_getcpuclockid Adhemerval Zanella
2021-08-26 14:27 ` Florian Weimer
2021-08-26 17:41 ` Adhemerval Zanella
2021-08-30 9:34 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 13/19] nptl: Use tidlock when accessing TID on pthread_getschedparam Adhemerval Zanella
2021-08-26 15:00 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 14/19] nptl: Use tidlock when accessing TID on pthread_setschedparam Adhemerval Zanella
2021-08-26 14:35 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 15/19] nptl: Use tidlock when accessing TID on pthread_getname_np Adhemerval Zanella
2021-08-26 14:38 ` Florian Weimer
2021-08-26 17:45 ` Adhemerval Zanella
2021-08-30 9:37 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 16/19] nptl: Use tidlock when accessing TID on pthread_setname_np Adhemerval Zanella
2021-08-23 19:50 ` [PATCH v2 17/19] nptl: Use tidlock when accessing TID on pthread_sigqueue Adhemerval Zanella
2021-08-26 14:43 ` Florian Weimer
2021-08-26 17:49 ` Adhemerval Zanella
2021-08-30 9:26 ` Florian Weimer
2021-08-23 19:50 ` [PATCH v2 18/19] nptl: Use tidlock when accessing TID on pthread_setschedprio Adhemerval Zanella
2021-08-23 19:50 ` [PATCH v2 19/19] nptl: Remove INVALID_TD_P Adhemerval Zanella
2021-08-26 9:30 ` Florian Weimer
2021-08-26 14:47 ` [PATCH v2 00/19] Fix various NPTL synchronization issues Florian Weimer
2021-08-26 18:19 ` 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=87r1eg5l6h.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=adhemerval.zanella@linaro.org \
--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).