[PATCH 6/6] nptl: Make pthread_{clock,timed}join{_np} act on all cancellation (BZ 33717)

Florian Weimer fweimer@redhat.com
Fri Dec 12 19:40:25 GMT 2025


* Adhemerval Zanella:

> The pthread_join/pthread_timedjoin_np/pthread_clockjoin_np will not act
> on cancellation if 1. some other thread is already waiting on the 'joinid'
> or 2. If the thread has already exited.

1. is undefined, so only 2 is relevant.

> diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
> index 6cdb710bc9..ddf10133c1 100644
> --- a/nptl/pthread_join_common.c
> +++ b/nptl/pthread_join_common.c
> @@ -28,6 +28,9 @@ __pthread_clockjoin_ex (pthread_t threadid, void **thread_return,
>                          const struct __timespec64 *abstime,
>                          bool cancel)
>  {
> +  if (cancel)
> +    __pthread_testcancel ();
> +
>    struct pthread *pd = (struct pthread *) threadid;

Should pthread_tryjoin_np, pthread_clockjoin_np be a cancellation
points?  For pthread_clockjoin_np yes, but it's more complicated for
pthread_tryjoin_np.

Any thoughts on that?  We could avoid making it a cancellation point
because pthread_tryjoin_np can never block.  So applications that need
to act upon cancellation probably already call pthread_testcancel.

> diff --git a/nptl/tst-cancel34.c b/nptl/tst-cancel34.c
> new file mode 100644
> index 0000000000..ad050c1dbb
> --- /dev/null
> +++ b/nptl/tst-cancel34.c

> +static int
> +do_test (void)
> +{
> +  do_test_common (pthread_join);
> +  do_test_common (pthread_timedjoin_np_wrapper);
> +  do_test_common (pthread_clockjoin_np_wrapper);

Please test pthread_tryjoin_np as well.

Thanks,
Florian



More information about the Libc-alpha mailing list