Patchwork [2/2] nptl: Add pthread_clockjoin_np

login
register
mail settings
Submitter Mike Crowe
Date June 28, 2019, 12:13 p.m.
Message ID <b062506121715def972680a512ef8afc661886c9.1561724011.git-series.mac@mcrowe.com>
Download mbox | patch
Permalink /patch/33471/
State New
Headers show

Comments

Mike Crowe - June 28, 2019, 12:13 p.m.
Introduce pthread_clockjoin_np as a version of pthread_timedjoin_np that
accepts a clockid_t parameter to indicate which clock the timeout should be
measured against. This mirrors the recently-added POSIX-proposed "clock"
wait functions.

	* NEWS: Mention addition of pthread_clockjoin_np along with other
	"clock" variants of existing "timed" functions.
	* sysdeps/nptl/pthread.h: Add declaration of pthread_clockjoin_np.
	* manual/threads.texi: Add pthread_clockjoin_np.
	* nptl/Makefile: Add pthread_clockjoin source file.  Add new join
	tests.
	* nptl/Versions: Add pthread_clockjoin_np.
	* nptl/PthreadP.h: Rename __pthread_timedjoin_ex to
	__pthread_clockjoin_ex and add clockid_t parameter.
	* nptl/pthread_join_common.c (clockwait_tid): Rename from
	timedwait_tid and add clockid parameter.  Use __clock_gettime
	passing supplied clockid rather than using __gettimeofday.  Perform
	relative timeout calculation entirely in timespec.
	(__pthread_clockjoin_ex): Rename from __pthread_timedjoin_ex and
	add clockid parameter to pass to clockwait_tid rather than
	timedwait_tid.
	* nptl/pthread_timedjoin.c (__pthread_timedjoin_np): Call
	__pthread_clockjoin_ex passing CLOCK_REALTIME as clockid.
	* nptl/pthread_join.c (__pthread_join): Call __pthread_clockjoin_ex
	and pass zero as unused clockid_t parameter.
	* nptl/pthread_tryjoin.c (__pthread_tryjoin_np): Likewise.
	* nptl/thrd_join.c (thrd_join): Likewise.
	* nptl/tst-join3.c (tf): Ensure that mutex is unlocked after use so
	that it cn be used again.  (do_test_clock): Rename from do_test and
	accept a clock parameter.  (do_test): Test pthread_timedjoin_np,
	pthread_clockjoin_np with CLOCK_REALTIME and pthread_clockjoin_np
	with CLOCK_MONOTONIC.
	* nptl/tst-join5.c (thread_join): Add support for testing
	pthread_clockjoin_np with both CLOCK_REALTIME and CLOCK_MONOTONIC.
	* nptl/tst-join10.c: Wrap tst-join5.c with
	USE_PTHREAD_CLOCKJOIN_NP_REALTIME.
	* nptl/tst-join11.c: Wrap tst-join5.c with
	USE_PTHREAD_CLOCKJOIN_NP_REALTIME and WAIT_IN_CHILD.
	* nptl/tst-join12.c: Wrap tst-join5.c with
	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC.
	* nptl/tst-join13.c: Wrap tst-join5.c with
	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC and WAIT_IN_CHILD.
	* sysdeps/unix/sysv/linux/aarch64/libpthread.abilist: Add
	pthread_clockjoin_np.
	* sysdeps/unix/sysv/linux/alpha/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/arm/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/csky/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/hppa/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/i386/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/ia64/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/microblaze/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/nios2/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist:
	Likewise.
	* sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sh/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist: Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist: Likewise.
---
 ChangeLog                                                       | 67 +++++++-
 NEWS                                                            |  9 +-
 manual/threads.texi                                             |  1 +-
 nptl/Makefile                                                   |  5 +-
 nptl/Versions                                                   |  1 +-
 nptl/pthreadP.h                                                 |  5 +-
 nptl/pthread_join.c                                             |  2 +-
 nptl/pthread_join_common.c                                      | 23 +-
 nptl/pthread_timedjoin.c                                        |  3 +-
 nptl/pthread_tryjoin.c                                          |  2 +-
 nptl/thrd_join.c                                                |  2 +-
 nptl/tst-join10.c                                               | 20 ++-
 nptl/tst-join11.c                                               | 21 ++-
 nptl/tst-join12.c                                               | 20 ++-
 nptl/tst-join13.c                                               | 21 ++-
 nptl/tst-join3.c                                                | 26 ++-
 nptl/tst-join5.c                                                | 20 +-
 sysdeps/nptl/pthread.h                                          | 11 +-
 sysdeps/unix/sysv/linux/aarch64/libpthread.abilist              |  1 +-
 sysdeps/unix/sysv/linux/alpha/libpthread.abilist                |  1 +-
 sysdeps/unix/sysv/linux/arm/libpthread.abilist                  |  1 +-
 sysdeps/unix/sysv/linux/csky/libpthread.abilist                 |  1 +-
 sysdeps/unix/sysv/linux/hppa/libpthread.abilist                 |  1 +-
 sysdeps/unix/sysv/linux/i386/libpthread.abilist                 |  1 +-
 sysdeps/unix/sysv/linux/ia64/libpthread.abilist                 |  1 +-
 sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist        |  1 +-
 sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist          |  1 +-
 sysdeps/unix/sysv/linux/microblaze/libpthread.abilist           |  1 +-
 sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist          |  1 +-
 sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist          |  1 +-
 sysdeps/unix/sysv/linux/nios2/libpthread.abilist                |  1 +-
 sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist    |  1 +-
 sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist |  1 +-
 sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist |  1 +-
 sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist           |  1 +-
 sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist         |  1 +-
 sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist         |  1 +-
 sysdeps/unix/sysv/linux/sh/libpthread.abilist                   |  1 +-
 sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist        |  1 +-
 sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist        |  1 +-
 sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist            |  1 +-
 sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist           |  1 +-
 42 files changed, 251 insertions(+), 32 deletions(-)
 create mode 100644 nptl/tst-join10.c
 create mode 100644 nptl/tst-join11.c
 create mode 100644 nptl/tst-join12.c
 create mode 100644 nptl/tst-join13.c
Yann Droneaud - June 28, 2019, 1:37 p.m.
Hi,

Le vendredi 28 juin 2019 à 13:13 +0100, Mike Crowe a écrit :
> Introduce pthread_clockjoin_np as a version of pthread_timedjoin_np that
> accepts a clockid_t parameter to indicate which clock the timeout should be
> measured against. This mirrors the recently-added POSIX-proposed "clock"
> wait functions.
> 
> 	* NEWS: Mention addition of pthread_clockjoin_np along with other
> 	"clock" variants of existing "timed" functions.
> 	* sysdeps/nptl/pthread.h: Add declaration of pthread_clockjoin_np.
> 	* manual/threads.texi: Add pthread_clockjoin_np.
> 	* nptl/Makefile: Add pthread_clockjoin source file.  Add new join
> 	tests.
> 	* nptl/Versions: Add pthread_clockjoin_np.
> 	* nptl/PthreadP.h: Rename __pthread_timedjoin_ex to
> 	__pthread_clockjoin_ex and add clockid_t parameter.
> 	* nptl/pthread_join_common.c (clockwait_tid): Rename from
> 	timedwait_tid and add clockid parameter.  Use __clock_gettime
> 	passing supplied clockid rather than using __gettimeofday.  Perform
> 	relative timeout calculation entirely in timespec.
> 	(__pthread_clockjoin_ex): Rename from __pthread_timedjoin_ex and
> 	add clockid parameter to pass to clockwait_tid rather than
> 	timedwait_tid.
> 	* nptl/pthread_timedjoin.c (__pthread_timedjoin_np): Call
> 	__pthread_clockjoin_ex passing CLOCK_REALTIME as clockid.
> 	* nptl/pthread_join.c (__pthread_join): Call __pthread_clockjoin_ex
> 	and pass zero as unused clockid_t parameter.

I would prefer -1, just because, on Linux, 0 is CLOCK_REALTIME.

> 	* nptl/pthread_tryjoin.c (__pthread_tryjoin_np): Likewise.
> 	* nptl/thrd_join.c (thrd_join): Likewise.
> 	* nptl/tst-join3.c (tf): Ensure that mutex is unlocked after use so
> 	that it cn be used again.  (do_test_clock): Rename from do_test and

can

> 	accept a clock parameter.  (do_test): Test pthread_timedjoin_np,
> 	pthread_clockjoin_np with CLOCK_REALTIME and pthread_clockjoin_np
> 	with CLOCK_MONOTONIC.
> 	* nptl/tst-join5.c (thread_join): Add support for testing
> 	pthread_clockjoin_np with both CLOCK_REALTIME and CLOCK_MONOTONIC.
> 	* nptl/tst-join10.c: Wrap tst-join5.c with
> 	USE_PTHREAD_CLOCKJOIN_NP_REALTIME.
> 	* nptl/tst-join11.c: Wrap tst-join5.c with
> 	USE_PTHREAD_CLOCKJOIN_NP_REALTIME and WAIT_IN_CHILD.
> 	* nptl/tst-join12.c: Wrap tst-join5.c with
> 	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC.
> 	* nptl/tst-join13.c: Wrap tst-join5.c with
> 	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC and WAIT_IN_CHILD.
> 	* sysdeps/unix/sysv/linux/aarch64/libpthread.abilist: Add
> 	pthread_clockjoin_np.
> 	* sysdeps/unix/sysv/linux/alpha/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/arm/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/csky/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/hppa/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/i386/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/ia64/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/microblaze/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/nios2/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist:
> 	Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist:
> 	Likewise.
> 	* sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist:
> 	Likewise.
> 	* sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/sh/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist: Likewise.
> 	* sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist: Likewise.
> ---
>  ChangeLog                                                       | 67 +++++++-
>  NEWS                                                            |  9 +-
>  manual/threads.texi                                             |  1 +-
>  nptl/Makefile                                                   |  5 +-
>  nptl/Versions                                                   |  1 +-
>  nptl/pthreadP.h                                                 |  5 +-
>  nptl/pthread_join.c                                             |  2 +-
>  nptl/pthread_join_common.c                                      | 23 +-
>  nptl/pthread_timedjoin.c                                        |  3 +-
>  nptl/pthread_tryjoin.c                                          |  2 +-
>  nptl/thrd_join.c                                                |  2 +-
>  nptl/tst-join10.c                                               | 20 ++-
>  nptl/tst-join11.c                                               | 21 ++-
>  nptl/tst-join12.c                                               | 20 ++-
>  nptl/tst-join13.c                                               | 21 ++-
>  nptl/tst-join3.c                                                | 26 ++-
>  nptl/tst-join5.c                                                | 20 +-
>  sysdeps/nptl/pthread.h                                          | 11 +-
>  sysdeps/unix/sysv/linux/aarch64/libpthread.abilist              |  1 +-
>  sysdeps/unix/sysv/linux/alpha/libpthread.abilist                |  1 +-
>  sysdeps/unix/sysv/linux/arm/libpthread.abilist                  |  1 +-
>  sysdeps/unix/sysv/linux/csky/libpthread.abilist                 |  1 +-
>  sysdeps/unix/sysv/linux/hppa/libpthread.abilist                 |  1 +-
>  sysdeps/unix/sysv/linux/i386/libpthread.abilist                 |  1 +-
>  sysdeps/unix/sysv/linux/ia64/libpthread.abilist                 |  1 +-
>  sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist        |  1 +-
>  sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist          |  1 +-
>  sysdeps/unix/sysv/linux/microblaze/libpthread.abilist           |  1 +-
>  sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist          |  1 +-
>  sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist          |  1 +-
>  sysdeps/unix/sysv/linux/nios2/libpthread.abilist                |  1 +-
>  sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist    |  1 +-
>  sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist |  1 +-
>  sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist |  1 +-
>  sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist           |  1 +-
>  sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist         |  1 +-
>  sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist         |  1 +-
>  sysdeps/unix/sysv/linux/sh/libpthread.abilist                   |  1 +-
>  sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist        |  1 +-
>  sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist        |  1 +-
>  sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist            |  1 +-
>  sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist           |  1 +-
>  42 files changed, 251 insertions(+), 32 deletions(-)
>  create mode 100644 nptl/tst-join10.c
>  create mode 100644 nptl/tst-join11.c
>  create mode 100644 nptl/tst-join12.c
>  create mode 100644 nptl/tst-join13.c
> 
> diff --git a/ChangeLog b/ChangeLog
> index fd51802..2c83de0 100644
> --- a/ChangeLog
> +++ b/ChangeLog
> @@ -1,4 +1,71 @@
>  2019-06-28  Mike Crowe  <mac@mcrowe.com>
> +	* NEWS: Mention addition of pthread_clockjoin_np along with other
> +	"clock" variants of existing "timed" functions.
> +	* sysdeps/nptl/pthread.h: Add declaration of pthread_clockjoin_np.
> +	* manual/threads.texi: Add pthread_clockjoin_np.
> +	* nptl/Makefile: Add pthread_clockjoin source file.  Add new join
> +	tests.
> +	* nptl/Versions: Add pthread_clockjoin_np.
> +	* nptl/PthreadP.h: Rename __pthread_timedjoin_ex to
> +	__pthread_clockjoin_ex and add clockid_t parameter.
> +	* nptl/pthread_join_common.c (clockwait_tid): Rename from
> +	timedwait_tid and add clockid parameter.  Use __clock_gettime
> +	passing supplied clockid rather than using __gettimeofday.  Perform
> +	relative timeout calculation entirely in timespec.
> +	(__pthread_clockjoin_ex): Rename from __pthread_timedjoin_ex and
> +	add clockid parameter to pass to clockwait_tid rather than
> +	timedwait_tid.
> +	* nptl/pthread_timedjoin.c (__pthread_timedjoin_np): Call
> +	__pthread_clockjoin_ex passing CLOCK_REALTIME as clockid.
> +	* nptl/pthread_join.c (__pthread_join): Call __pthread_clockjoin_ex
> +	and pass zero as unused clockid_t parameter.
> +	* nptl/pthread_tryjoin.c (__pthread_tryjoin_np): Likewise.
> +	* nptl/thrd_join.c (thrd_join): Likewise.
> +	* nptl/tst-join3.c (tf): Ensure that mutex is unlocked after use so
> +	that it cn be used again.  (do_test_clock): Rename from do_test and

can

> +	accept a clock parameter.  (do_test): Test pthread_timedjoin_np,
> +	pthread_clockjoin_np with CLOCK_REALTIME and pthread_clockjoin_np
> +	with CLOCK_MONOTONIC.
> +	* nptl/tst-join5.c (thread_join): Add support for testing
> +	pthread_clockjoin_np with both CLOCK_REALTIME and CLOCK_MONOTONIC.
> +	* nptl/tst-join10.c: Wrap tst-join5.c with
> +	USE_PTHREAD_CLOCKJOIN_NP_REALTIME.
> +	* nptl/tst-join11.c: Wrap tst-join5.c with
> +	USE_PTHREAD_CLOCKJOIN_NP_REALTIME and WAIT_IN_CHILD.
> +	* nptl/tst-join12.c: Wrap tst-join5.c with
> +	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC.
> +	* nptl/tst-join13.c: Wrap tst-join5.c with
> +	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC and WAIT_IN_CHILD.
> +	* sysdeps/unix/sysv/linux/aarch64/libpthread.abilist: Add
> +	pthread_clockjoin_np.
> +	* sysdeps/unix/sysv/linux/alpha/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/arm/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/csky/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/hppa/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/i386/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/ia64/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/microblaze/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/nios2/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist:
> +	Likewise.
> +	* sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist:
> +	Likewise.
> +	* sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist:
> +	Likewise.
> +	* sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/sh/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist: Likewise.
> +	* sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist: Likewise.
> +
> +2019-06-28  Mike Crowe  <mac@mcrowe.com>
>  
>  	* nptl/tst-join3.c: Use libsupport.
>  
> diff --git a/NEWS b/NEWS
> index 59dd8b3..07b9e73 100644
> --- a/NEWS
> +++ b/NEWS
> @@ -36,10 +36,11 @@ Major new features:
>  
>  * Add new POSIX-proposed pthread_cond_clockwait, pthread_mutex_clocklock,
>    pthread_rwlock_clockrdlock, pthread_rwlock_clockwrlock and sem_clockwait
> -  functions.  These behave similarly to their "timed" equivalents, but also
> -  accept a clockid_t parameter to determine which clock their timeout should
> -  be measured against.  All functions allow waiting against CLOCK_MONOTONIC
> -  and CLOCK_REALTIME.  The decision of which clock to be used is made at the
> +  functions along with glibc-specific pthread_clockjoin_np.  These behave
> +  similarly to their "timed" equivalents, but also accept a clockid_t
> +  parameter to determine which clock their timeout should be measured
> +  against.  All functions allow waiting against CLOCK_MONOTONIC and
> +  CLOCK_REALTIME.  The decision of which clock to be used is made at the
>    time of the wait (unlike with pthread_condattr_setclock, which requires
>    the clock choice at initialization time).
>  
> diff --git a/manual/threads.texi b/manual/threads.texi
> index 0e5e84a..c8911da 100644
> --- a/manual/threads.texi
> +++ b/manual/threads.texi
> @@ -845,5 +845,6 @@ returned.
>  @c pthread_spin_unlock
>  @c pthread_testcancel
>  @c pthread_timedjoin_np
> +@c pthread_clockjoin_np
>  @c pthread_tryjoin_np
>  @c pthread_yield
> diff --git a/nptl/Makefile b/nptl/Makefile
> index a2d25fb..85e98c4 100644
> --- a/nptl/Makefile
> +++ b/nptl/Makefile
> @@ -49,7 +49,7 @@ pthread-compat-wrappers = \
>  libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
>  		      pthread_create pthread_exit pthread_detach \
>  		      pthread_join pthread_tryjoin pthread_timedjoin \
> -		      pthread_join_common \
> +		      pthread_clockjoin pthread_join_common \
>  		      compat-pthread_self pthread_equal pthread_yield \
>  		      pthread_getconcurrency pthread_setconcurrency \
>  		      pthread_getschedparam pthread_setschedparam \
> @@ -190,6 +190,7 @@ CFLAGS-forward.c += -fexceptions
>  CFLAGS-pthread_testcancel.c += -fexceptions
>  CFLAGS-pthread_join.c += -fexceptions -fasynchronous-unwind-tables
>  CFLAGS-pthread_timedjoin.c += -fexceptions -fasynchronous-unwind-tables
> +CFLAGS-pthread_clockjoin.c += -fexceptions -fasynchronous-unwind-tables
>  CFLAGS-pthread_once.c += $(uses-callbacks) -fexceptions \
>  			-fasynchronous-unwind-tables
>  CFLAGS-pthread_cond_wait.c += -fexceptions -fasynchronous-unwind-tables
> @@ -274,7 +275,7 @@ tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
>  	tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \
>  	tst-raise1 \
>  	tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 tst-join7 \
> -	tst-join8 tst-join9 \
> +	tst-join8 tst-join9 tst-join10 tst-join11 tst-join12 tst-join13 \
>  	tst-detach1 \
>  	tst-eintr2 tst-eintr3 tst-eintr4 tst-eintr5 \
>  	tst-tsd1 tst-tsd2 tst-tsd3 tst-tsd4 tst-tsd5 tst-tsd6 \
> diff --git a/nptl/Versions b/nptl/Versions
> index e903b84..443d4fb 100644
> --- a/nptl/Versions
> +++ b/nptl/Versions
> @@ -281,6 +281,7 @@ libpthread {
>      sem_clockwait; pthread_cond_clockwait;
>      pthread_rwlock_clockrdlock; pthread_rwlock_clockwrlock;
>      pthread_mutex_clocklock;
> +    pthread_clockjoin_np;
>    }
>  
>    GLIBC_PRIVATE {
> diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
> index d80662a..ea7b5bf 100644
> --- a/nptl/pthreadP.h
> +++ b/nptl/pthreadP.h
> @@ -475,7 +475,8 @@ extern int __pthread_setcanceltype (int type, int *oldtype);
>  extern int __pthread_enable_asynccancel (void) attribute_hidden;
>  extern void __pthread_disable_asynccancel (int oldtype) attribute_hidden;
>  extern void __pthread_testcancel (void);
> -extern int __pthread_timedjoin_ex (pthread_t, void **, const struct timespec *,
> +extern int __pthread_clockjoin_ex (pthread_t, void **,
> +                                   clockid_t, const struct timespec *,
>  				   bool);
>  
>  #if IS_IN (libpthread)
> @@ -495,7 +496,7 @@ hidden_proto (__pthread_setcancelstate)
>  hidden_proto (__pthread_testcancel)
>  hidden_proto (__pthread_mutexattr_init)
>  hidden_proto (__pthread_mutexattr_settype)
> -hidden_proto (__pthread_timedjoin_ex)
> +hidden_proto (__pthread_clockjoin_ex)
>  #endif
>  
>  extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
> diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
> index 379ddc8..0fb0aaa 100644
> --- a/nptl/pthread_join.c
> +++ b/nptl/pthread_join.c
> @@ -21,6 +21,6 @@
>  int
>  __pthread_join (pthread_t threadid, void **thread_return)
>  {
> -  return __pthread_timedjoin_ex (threadid, thread_return, NULL, true);
> +  return __pthread_clockjoin_ex (threadid, thread_return, 0, NULL, true);
>  }
>  weak_alias (__pthread_join, pthread_join)
> diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
> index 5224ee2..c3538f9 100644
> --- a/nptl/pthread_join_common.c
> +++ b/nptl/pthread_join_common.c
> @@ -36,7 +36,7 @@ cleanup (void *arg)
>     afterwards.  The kernel up to version 3.16.3 does not use the private futex
>     operations for futex wake-up when the clone terminates.  */
>  static int
> -timedwait_tid (pid_t *tidp, const struct timespec *abstime)
> +clockwait_tid (pid_t *tidp, clockid_t clockid, const struct timespec *abstime)
>  {
>    pid_t tid;
>  
> @@ -46,15 +46,17 @@ timedwait_tid (pid_t *tidp, const struct timespec *abstime)
>    /* Repeat until thread terminated.  */
>    while ((tid = *tidp) != 0)
>      {
> -      struct timeval tv;
> +      struct timespec ts;
>        struct timespec rt;
>  
> -      /* Get the current time.  */
> -      __gettimeofday (&tv, NULL);
> +      /* Get the current time. This can only fail if clockid is
> +         invalid. */
> +      if (__glibc_unlikely (__clock_gettime (clockid, &ts)))
> +        return EINVAL;
>  
>        /* Compute relative timeout.  */
> -      rt.tv_sec = abstime->tv_sec - tv.tv_sec;
> -      rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
> +      rt.tv_sec = abstime->tv_sec - ts.tv_sec;
> +      rt.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
>        if (rt.tv_nsec < 0)
>          {
>            rt.tv_nsec += 1000000000;
> @@ -77,7 +79,8 @@ timedwait_tid (pid_t *tidp, const struct timespec *abstime)
>  }
>  
>  int
> -__pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
> +__pthread_clockjoin_ex (pthread_t threadid, void **thread_return,
> +                        clockid_t clockid,
>  			const struct timespec *abstime, bool block)
>  {
>    struct pthread *pd = (struct pthread *) threadid;
> @@ -122,7 +125,7 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
>  
>    /* BLOCK waits either indefinitely or based on an absolute time.  POSIX also
>       states a cancellation point shall occur for pthread_join, and we use the
> -     same rationale for posix_timedjoin_np.  Both timedwait_tid and the futex
> +     same rationale for posix_timedjoin_np.  Both clockwait_tid and the futex
>       call use the cancellable variant.  */
>    if (block)
>      {
> @@ -132,7 +135,7 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
>        pthread_cleanup_push (cleanup, &pd->joinid);
>  
>        if (abstime != NULL)
> -	result = timedwait_tid (&pd->tid, abstime);
> +	result = clockwait_tid (&pd->tid, clockid, abstime);
>        else
>  	{
>  	  pid_t tid;
> @@ -165,4 +168,4 @@ __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
>  
>    return result;
>  }
> -hidden_def (__pthread_timedjoin_ex)
> +hidden_def (__pthread_clockjoin_ex)
> diff --git a/nptl/pthread_timedjoin.c b/nptl/pthread_timedjoin.c
> index 323c0ff..55a0cb9 100644
> --- a/nptl/pthread_timedjoin.c
> +++ b/nptl/pthread_timedjoin.c
> @@ -22,6 +22,7 @@ int
>  __pthread_timedjoin_np (pthread_t threadid, void **thread_return,
>  			const struct timespec *abstime)
>  {
> -  return __pthread_timedjoin_ex (threadid, thread_return, abstime, true);
> +  return __pthread_clockjoin_ex (threadid, thread_return,
> +                                 CLOCK_REALTIME, abstime, true);
>  }
>  weak_alias (__pthread_timedjoin_np, pthread_timedjoin_np)
> diff --git a/nptl/pthread_tryjoin.c b/nptl/pthread_tryjoin.c
> index 7dbf228..d76c4a6 100644
> --- a/nptl/pthread_tryjoin.c
> +++ b/nptl/pthread_tryjoin.c
> @@ -28,5 +28,5 @@ pthread_tryjoin_np (pthread_t threadid, void **thread_return)
>  
>    /* If pd->tid == 0 then lll_wait_tid will not block on futex
>       operation.  */
> -  return __pthread_timedjoin_ex (threadid, thread_return, NULL, false);
> +  return __pthread_clockjoin_ex (threadid, thread_return, 0, NULL, false);
>  }
> diff --git a/nptl/thrd_join.c b/nptl/thrd_join.c
> index b3df236..64b0d08 100644
> --- a/nptl/thrd_join.c
> +++ b/nptl/thrd_join.c
> @@ -22,7 +22,7 @@ int
>  thrd_join (thrd_t thr, int *res)
>  {
>    void *pthread_res;
> -  int err_code = __pthread_timedjoin_ex (thr, &pthread_res, NULL, true);
> +  int err_code = __pthread_clockjoin_ex (thr, &pthread_res, 0, NULL, true);
>    if (res)
>     *res = (int) (uintptr_t) pthread_res;
>  
> diff --git a/nptl/tst-join10.c b/nptl/tst-join10.c
> new file mode 100644
> index 0000000..a222dd1
> --- /dev/null
> +++ b/nptl/tst-join10.c
> @@ -0,0 +1,20 @@
> +/* Check if pthread_clockjoin_np is a cancellation entrypoint.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>;.  */
> +
> +#define USE_PTHREAD_CLOCKJOIN_NP_REALTIME 1
> +#include <nptl/tst-join5.c>
> diff --git a/nptl/tst-join11.c b/nptl/tst-join11.c
> new file mode 100644
> index 0000000..341588a
> --- /dev/null
> +++ b/nptl/tst-join11.c
> @@ -0,0 +1,21 @@
> +/* Check if pthread_clockjoin_np is a cancellation entrypoint.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>;.  */
> +
> +#define USE_PTHREAD_CLOCKJOIN_NP_REALTIME 1
> +#define WAIT_IN_CHILD 1
> +#include <nptl/tst-join5.c>
> diff --git a/nptl/tst-join12.c b/nptl/tst-join12.c
> new file mode 100644
> index 0000000..44592dc
> --- /dev/null
> +++ b/nptl/tst-join12.c
> @@ -0,0 +1,20 @@
> +/* Check if pthread_clockjoin_np is a cancellation entrypoint.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>;.  */
> +
> +#define USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC 1
> +#include <nptl/tst-join5.c>
> diff --git a/nptl/tst-join13.c b/nptl/tst-join13.c
> new file mode 100644
> index 0000000..d4e49d5
> --- /dev/null
> +++ b/nptl/tst-join13.c
> @@ -0,0 +1,21 @@
> +/* Check if pthread_clockjoin_np is a cancellation entrypoint.
> +   Copyright (C) 2019 Free Software Foundation, Inc.
> +   This file is part of the GNU C Library.
> +
> +   The GNU C Library is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU Lesser General Public
> +   License as published by the Free Software Foundation; either
> +   version 2.1 of the License, or (at your option) any later version.
> +
> +   The GNU C Library is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> +   Lesser General Public License for more details.
> +
> +   You should have received a copy of the GNU Lesser General Public
> +   License along with the GNU C Library; if not, see
> +   <http://www.gnu.org/licenses/>;.  */
> +
> +#define USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC 1
> +#define WAIT_IN_CHILD 1
> +#include <nptl/tst-join5.c>
> diff --git a/nptl/tst-join3.c b/nptl/tst-join3.c
> index 460b862..2471de0 100644
> --- a/nptl/tst-join3.c
> +++ b/nptl/tst-join3.c
> @@ -28,6 +28,8 @@
>  #include <support/xtime.h>
>  
>  
> +#define CLOCK_USE_TIMEDJOIN (-1)
> +
>  static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
>  
>  
> @@ -35,19 +37,23 @@ static void *
>  tf (void *arg)
>  {
>    xpthread_mutex_lock (&lock);
> +  xpthread_mutex_unlock (&lock);
>  
>    return (void *) 42l;
>  }
>  
>  
>  static int
> -do_test (void)
> +do_test_clock (clockid_t clockid)
>  {
> +  const clockid_t clockid_for_get =
> +    (clockid == CLOCK_USE_TIMEDJOIN) ? CLOCK_REALTIME : clockid;

I would prefer do_test_clock() having another parameter to enable usage
of pthread_clockjoin_np() than having a "fake" clock identifier used as
a boolean.

> +
>    xpthread_mutex_lock (&lock);
>    pthread_t th = xpthread_create (NULL, tf, NULL);
>  
>    void *status;
> -  struct timespec timeout = timespec_add (xclock_now (CLOCK_REALTIME),
> +  struct timespec timeout = timespec_add (xclock_now (clockid_for_get),
>                                            make_timespec (0, 200000000));
>  
>    int val = pthread_timedjoin_np (th, &status, &timeout);
> @@ -57,10 +63,13 @@ do_test (void)
>  
>    while (1)
>      {
> -      timeout = timespec_add (xclock_now (CLOCK_REALTIME),
> +      timeout = timespec_add (xclock_now (clockid_for_get),
>                                make_timespec (0, 200000000));
>  
> -      val = pthread_timedjoin_np (th, &status, &timeout);
> +      if (clockid == CLOCK_USE_TIMEDJOIN)
> +        val = pthread_timedjoin_np (th, &status, &timeout);
> +      else
> +        val = pthread_clockjoin_np (th, &status, clockid, &timeout);
>        if (val == 0)
>  	break;
>  
> @@ -73,4 +82,13 @@ do_test (void)
>    return 0;
>  }
>  
> +static int
> +do_test (void)
> +{
> +  do_test_clock (CLOCK_USE_TIMEDJOIN);
> +  do_test_clock (CLOCK_REALTIME);
> +  do_test_clock (CLOCK_MONOTONIC);
> +  return 0;
> +}
> +
>  #include <support/test-driver.c>
> diff --git a/nptl/tst-join5.c b/nptl/tst-join5.c
> index 39f74dc..dd098fd 100644
> --- a/nptl/tst-join5.c
> +++ b/nptl/tst-join5.c
> @@ -24,7 +24,9 @@
>  #include <unistd.h>
>  
>  #include <support/check.h>
> +#include <support/timespec.h>
>  #include <support/xthread.h>
> +#include <support/xtime.h>
>  
>  static void
>  wait_code (void)
> @@ -42,12 +44,18 @@ static pthread_barrier_t b;
>  static int
>  thread_join (pthread_t thread, void **retval)
>  {
> -#ifdef USE_PTHREAD_TIMEDJOIN_NP
> -  struct timespec tv;
> -  TEST_COMPARE (clock_gettime (CLOCK_REALTIME, &tv), 0);
> -  /* Arbitrary large timeout to make it act as pthread_join.  */
> -  tv.tv_sec += 1000;
> -  return pthread_timedjoin_np ((pthread_t) thread, retval, &tv);
> +#if defined USE_PTHREAD_TIMEDJOIN_NP
> +  const struct timespec ts = timespec_add (xclock_now (CLOCK_REALTIME),
> +                                           make_timespec (1000, 0));
> +  return pthread_timedjoin_np ((pthread_t) thread, retval, &ts);
> +#elif defined USE_PTHREAD_CLOCKJOIN_NP_REALTIME
> +  const struct timespec ts = timespec_add (xclock_now (CLOCK_REALTIME),
> +                                           make_timespec (1000, 0));
> +  return pthread_clockjoin_np ((pthread_t) thread, retval, CLOCK_REALTIME, &ts);
> +#elif defined USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC
> +  const struct timespec ts = timespec_add (xclock_now (CLOCK_MONOTONIC),
> +                                           make_timespec (1000, 0));
> +  return pthread_clockjoin_np ((pthread_t) thread, retval, CLOCK_MONOTONIC, &ts);
>  #else
>    return pthread_join ((pthread_t) thread, retval);
>  #endif
> diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
> index a767d6f..00d996c 100644
> --- a/sysdeps/nptl/pthread.h
> +++ b/sysdeps/nptl/pthread.h
> @@ -263,6 +263,17 @@ extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
>     __THROW.  */
>  extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
>  				 const struct timespec *__abstime);
> +
> +/* Make calling thread wait for termination of the thread TH, but only
> +   until TIMEOUT measured against the clock specified by CLOCKID.  The
> +   exit status of the thread is stored in *THREAD_RETURN, if
> +   THREAD_RETURN is not NULL.
> +
> +   This function is a cancellation point and therefore not marked with
> +   __THROW.  */
> +extern int pthread_clockjoin_np (pthread_t __th, void **__thread_return,
> +                                 clockid_t clockid,
> +				 const struct timespec *__abstime);

What's the behavior when __abstime is NULL ?

pthread_timedjoin_np()'s code seems to behave like pthread_join() if
__abstime is NULL. This behavior is fine but not documented.

>  #endif
>  
>  /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
> diff --git a/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist b/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist
> index 69f48bf..8b4c928 100644
> --- a/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist
> @@ -243,6 +243,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/alpha/libpthread.abilist b/sysdeps/unix/sysv/linux/alpha/libpthread.abilist
> index 7aa6416..1637215 100644
> --- a/sysdeps/unix/sysv/linux/alpha/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/alpha/libpthread.abilist
> @@ -255,6 +255,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/arm/libpthread.abilist b/sysdeps/unix/sysv/linux/arm/libpthread.abilist
> index 3d2287b..d5f393a 100644
> --- a/sysdeps/unix/sysv/linux/arm/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/arm/libpthread.abilist
> @@ -27,6 +27,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/csky/libpthread.abilist b/sysdeps/unix/sysv/linux/csky/libpthread.abilist
> index 52373fc..47f3ff2 100644
> --- a/sysdeps/unix/sysv/linux/csky/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/csky/libpthread.abilist
> @@ -233,6 +233,7 @@ GLIBC_2.29 tss_set F
>  GLIBC_2.29 wait F
>  GLIBC_2.29 waitpid F
>  GLIBC_2.29 write F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/hppa/libpthread.abilist b/sysdeps/unix/sysv/linux/hppa/libpthread.abilist
> index d11e150..6e39a7d 100644
> --- a/sysdeps/unix/sysv/linux/hppa/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/hppa/libpthread.abilist
> @@ -245,6 +245,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/i386/libpthread.abilist b/sysdeps/unix/sysv/linux/i386/libpthread.abilist
> index 1b385ca..40a3963 100644
> --- a/sysdeps/unix/sysv/linux/i386/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/i386/libpthread.abilist
> @@ -253,6 +253,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/ia64/libpthread.abilist b/sysdeps/unix/sysv/linux/ia64/libpthread.abilist
> index bde9948..fae4241 100644
> --- a/sysdeps/unix/sysv/linux/ia64/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/ia64/libpthread.abilist
> @@ -247,6 +247,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
> index 3d2287b..d5f393a 100644
> --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
> @@ -27,6 +27,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
> index 1b385ca..40a3963 100644
> --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
> @@ -253,6 +253,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist b/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
> index f0365f3..6f9e18a 100644
> --- a/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
> @@ -243,6 +243,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist b/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
> index b1dff8e..4db6c83 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
> @@ -255,6 +255,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist b/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
> index b1dff8e..4db6c83 100644
> --- a/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
> @@ -255,6 +255,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/nios2/libpthread.abilist b/sysdeps/unix/sysv/linux/nios2/libpthread.abilist
> index 0150ea3..99a75b6 100644
> --- a/sysdeps/unix/sysv/linux/nios2/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/nios2/libpthread.abilist
> @@ -241,6 +241,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
> index 9e71e17..9316ec7 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
> @@ -255,6 +255,7 @@ GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
>  GLIBC_2.3.4 siglongjmp F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
> index 393ec87..564abdc 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
> @@ -246,6 +246,7 @@ GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
>  GLIBC_2.3.4 siglongjmp F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
> index 69f48bf..8b4c928 100644
> --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
> @@ -243,6 +243,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
> index 7dab4e5..df81182 100644
> --- a/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
> @@ -235,6 +235,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
> index 7db2a0c..ebe8962 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
> @@ -255,6 +255,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
> index 7c10bb2..91f4857 100644
> --- a/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
> @@ -247,6 +247,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/sh/libpthread.abilist b/sysdeps/unix/sysv/linux/sh/libpthread.abilist
> index d11e150..6e39a7d 100644
> --- a/sysdeps/unix/sysv/linux/sh/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/sh/libpthread.abilist
> @@ -245,6 +245,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
> index 7aa6416..1637215 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
> @@ -255,6 +255,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
> index bde9948..fae4241 100644
> --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
> @@ -247,6 +247,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
> index c5ecb12..72bdb17 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
> @@ -245,6 +245,7 @@ GLIBC_2.3.4 pthread_attr_setaffinity_np F
>  GLIBC_2.3.4 pthread_getaffinity_np F
>  GLIBC_2.3.4 pthread_setaffinity_np F
>  GLIBC_2.3.4 pthread_setschedprio F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F
> diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
> index a7ff3fb..b738283 100644
> --- a/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
> +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
> @@ -243,6 +243,7 @@ GLIBC_2.28 tss_create F
>  GLIBC_2.28 tss_delete F
>  GLIBC_2.28 tss_get F
>  GLIBC_2.28 tss_set F
> +GLIBC_2.30 pthread_clockjoin_np F
>  GLIBC_2.30 pthread_cond_clockwait F
>  GLIBC_2.30 pthread_mutex_clocklock F
>  GLIBC_2.30 pthread_rwlock_clockrdlock F

Regards.
Mike Crowe - July 16, 2019, 9:59 a.m.
On Friday 28 June 2019 at 15:37:20 +0200, Yann Droneaud wrote:
> Hi,
> 
> Le vendredi 28 juin 2019 à 13:13 +0100, Mike Crowe a écrit :
> > Introduce pthread_clockjoin_np as a version of pthread_timedjoin_np that
> > accepts a clockid_t parameter to indicate which clock the timeout should be
> > measured against. This mirrors the recently-added POSIX-proposed "clock"
> > wait functions.
> > 
> > 	* NEWS: Mention addition of pthread_clockjoin_np along with other
> > 	"clock" variants of existing "timed" functions.
> > 	* sysdeps/nptl/pthread.h: Add declaration of pthread_clockjoin_np.
> > 	* manual/threads.texi: Add pthread_clockjoin_np.
> > 	* nptl/Makefile: Add pthread_clockjoin source file.  Add new join
> > 	tests.
> > 	* nptl/Versions: Add pthread_clockjoin_np.
> > 	* nptl/PthreadP.h: Rename __pthread_timedjoin_ex to
> > 	__pthread_clockjoin_ex and add clockid_t parameter.
> > 	* nptl/pthread_join_common.c (clockwait_tid): Rename from
> > 	timedwait_tid and add clockid parameter.  Use __clock_gettime
> > 	passing supplied clockid rather than using __gettimeofday.  Perform
> > 	relative timeout calculation entirely in timespec.
> > 	(__pthread_clockjoin_ex): Rename from __pthread_timedjoin_ex and
> > 	add clockid parameter to pass to clockwait_tid rather than
> > 	timedwait_tid.
> > 	* nptl/pthread_timedjoin.c (__pthread_timedjoin_np): Call
> > 	__pthread_clockjoin_ex passing CLOCK_REALTIME as clockid.
> > 	* nptl/pthread_join.c (__pthread_join): Call __pthread_clockjoin_ex
> > 	and pass zero as unused clockid_t parameter.
> 
> I would prefer -1, just because, on Linux, 0 is CLOCK_REALTIME.

Previously, Adhemerval Zanella had said[1] that they preferred using zero.
Having said that, I appear to have used CLOCK_REALTIME in a few places in
e996fa72a9bad0be72c6d3d99d9faba5efddf44f at least.

Mike.

[1] https://sourceware.org/ml/libc-alpha/2017-06/msg01491.html
Mike Crowe - Sept. 11, 2019, 2:22 p.m.
On Friday 28 June 2019 at 15:37:20 +0200, Yann Droneaud wrote:
> Le vendredi 28 juin 2019 à 13:13 +0100, Mike Crowe a écrit :
> > Introduce pthread_clockjoin_np as a version of pthread_timedjoin_np that
> > accepts a clockid_t parameter to indicate which clock the timeout should be
> > measured against. This mirrors the recently-added POSIX-proposed "clock"
> > wait functions.

[snip]

> > diff --git a/nptl/tst-join3.c b/nptl/tst-join3.c
> > index 460b862..2471de0 100644
> > --- a/nptl/tst-join3.c
> > +++ b/nptl/tst-join3.c
> > @@ -28,6 +28,8 @@
> >  #include <support/xtime.h>
> >  
> >  
> > +#define CLOCK_USE_TIMEDJOIN (-1)
> > +
> >  static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
> >  
> >  
> > @@ -35,19 +37,23 @@ static void *
> >  tf (void *arg)
> >  {
> >    xpthread_mutex_lock (&lock);
> > +  xpthread_mutex_unlock (&lock);
> >  
> >    return (void *) 42l;
> >  }
> >  
> >  
> >  static int
> > -do_test (void)
> > +do_test_clock (clockid_t clockid)
> >  {
> > +  const clockid_t clockid_for_get =
> > +    (clockid == CLOCK_USE_TIMEDJOIN) ? CLOCK_REALTIME : clockid;
> 
> I would prefer do_test_clock() having another parameter to enable usage
> of pthread_clockjoin_np() than having a "fake" clock identifier used as
> a boolean.

The fake clockid is the form I've used in all the other tests I added for
the new clocklock/clockwait functions in glibc v2.30. It's not really being
used as a boolean. Using a separate boolean would not be orthogonal to the
clockid - it would permit conflicting parameters to be specified where the
boolean could indicate that pthread_timedjoin_np should be tested with
CLOCK_MONOTONIC.

[snip]

> > diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
> > index a767d6f..00d996c 100644
> > --- a/sysdeps/nptl/pthread.h
> > +++ b/sysdeps/nptl/pthread.h
> > @@ -263,6 +263,17 @@ extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
> >     __THROW.  */
> >  extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
> >  				 const struct timespec *__abstime);
> > +
> > +/* Make calling thread wait for termination of the thread TH, but only
> > +   until TIMEOUT measured against the clock specified by CLOCKID.  The
> > +   exit status of the thread is stored in *THREAD_RETURN, if
> > +   THREAD_RETURN is not NULL.
> > +
> > +   This function is a cancellation point and therefore not marked with
> > +   __THROW.  */
> > +extern int pthread_clockjoin_np (pthread_t __th, void **__thread_return,
> > +                                 clockid_t clockid,
> > +				 const struct timespec *__abstime);
> 
> What's the behavior when __abstime is NULL ?

Currently it's the same as pthread_timedjoin_np. I shall add a test for
that to ensure that it isn't broken.

> pthread_timedjoin_np()'s code seems to behave like pthread_join() if
> __abstime is NULL. This behavior is fine but not documented.

The old LinuxThreads phread_timedjoin_np man page doesn't mention what
happens when __abstime is NULL. There don't appear to be any NPTL man
pages. :(

pthread_timedjoin_np isn't currently documented in the glibc threads.texi
file. I will try to write some documentation there for it. It's too late to
change the behaviour now, of course.

For pthread_clockjoin_np there's no backward compatibility problem, so I
could make it behave the same as pthread_timedjoin_np or always return
EINVAL. I'm probably inclined to keep it the same.

Thanks for the review.

Mike.

Patch

diff --git a/ChangeLog b/ChangeLog
index fd51802..2c83de0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,71 @@ 
 2019-06-28  Mike Crowe  <mac@mcrowe.com>
+	* NEWS: Mention addition of pthread_clockjoin_np along with other
+	"clock" variants of existing "timed" functions.
+	* sysdeps/nptl/pthread.h: Add declaration of pthread_clockjoin_np.
+	* manual/threads.texi: Add pthread_clockjoin_np.
+	* nptl/Makefile: Add pthread_clockjoin source file.  Add new join
+	tests.
+	* nptl/Versions: Add pthread_clockjoin_np.
+	* nptl/PthreadP.h: Rename __pthread_timedjoin_ex to
+	__pthread_clockjoin_ex and add clockid_t parameter.
+	* nptl/pthread_join_common.c (clockwait_tid): Rename from
+	timedwait_tid and add clockid parameter.  Use __clock_gettime
+	passing supplied clockid rather than using __gettimeofday.  Perform
+	relative timeout calculation entirely in timespec.
+	(__pthread_clockjoin_ex): Rename from __pthread_timedjoin_ex and
+	add clockid parameter to pass to clockwait_tid rather than
+	timedwait_tid.
+	* nptl/pthread_timedjoin.c (__pthread_timedjoin_np): Call
+	__pthread_clockjoin_ex passing CLOCK_REALTIME as clockid.
+	* nptl/pthread_join.c (__pthread_join): Call __pthread_clockjoin_ex
+	and pass zero as unused clockid_t parameter.
+	* nptl/pthread_tryjoin.c (__pthread_tryjoin_np): Likewise.
+	* nptl/thrd_join.c (thrd_join): Likewise.
+	* nptl/tst-join3.c (tf): Ensure that mutex is unlocked after use so
+	that it cn be used again.  (do_test_clock): Rename from do_test and
+	accept a clock parameter.  (do_test): Test pthread_timedjoin_np,
+	pthread_clockjoin_np with CLOCK_REALTIME and pthread_clockjoin_np
+	with CLOCK_MONOTONIC.
+	* nptl/tst-join5.c (thread_join): Add support for testing
+	pthread_clockjoin_np with both CLOCK_REALTIME and CLOCK_MONOTONIC.
+	* nptl/tst-join10.c: Wrap tst-join5.c with
+	USE_PTHREAD_CLOCKJOIN_NP_REALTIME.
+	* nptl/tst-join11.c: Wrap tst-join5.c with
+	USE_PTHREAD_CLOCKJOIN_NP_REALTIME and WAIT_IN_CHILD.
+	* nptl/tst-join12.c: Wrap tst-join5.c with
+	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC.
+	* nptl/tst-join13.c: Wrap tst-join5.c with
+	USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC and WAIT_IN_CHILD.
+	* sysdeps/unix/sysv/linux/aarch64/libpthread.abilist: Add
+	pthread_clockjoin_np.
+	* sysdeps/unix/sysv/linux/alpha/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/arm/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/csky/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/hppa/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/i386/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/ia64/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/microblaze/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/nios2/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist:
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist:
+	Likewise.
+	* sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist:
+	Likewise.
+	* sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/sh/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist: Likewise.
+	* sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist: Likewise.
+
+2019-06-28  Mike Crowe  <mac@mcrowe.com>
 
 	* nptl/tst-join3.c: Use libsupport.
 
diff --git a/NEWS b/NEWS
index 59dd8b3..07b9e73 100644
--- a/NEWS
+++ b/NEWS
@@ -36,10 +36,11 @@  Major new features:
 
 * Add new POSIX-proposed pthread_cond_clockwait, pthread_mutex_clocklock,
   pthread_rwlock_clockrdlock, pthread_rwlock_clockwrlock and sem_clockwait
-  functions.  These behave similarly to their "timed" equivalents, but also
-  accept a clockid_t parameter to determine which clock their timeout should
-  be measured against.  All functions allow waiting against CLOCK_MONOTONIC
-  and CLOCK_REALTIME.  The decision of which clock to be used is made at the
+  functions along with glibc-specific pthread_clockjoin_np.  These behave
+  similarly to their "timed" equivalents, but also accept a clockid_t
+  parameter to determine which clock their timeout should be measured
+  against.  All functions allow waiting against CLOCK_MONOTONIC and
+  CLOCK_REALTIME.  The decision of which clock to be used is made at the
   time of the wait (unlike with pthread_condattr_setclock, which requires
   the clock choice at initialization time).
 
diff --git a/manual/threads.texi b/manual/threads.texi
index 0e5e84a..c8911da 100644
--- a/manual/threads.texi
+++ b/manual/threads.texi
@@ -845,5 +845,6 @@  returned.
 @c pthread_spin_unlock
 @c pthread_testcancel
 @c pthread_timedjoin_np
+@c pthread_clockjoin_np
 @c pthread_tryjoin_np
 @c pthread_yield
diff --git a/nptl/Makefile b/nptl/Makefile
index a2d25fb..85e98c4 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -49,7 +49,7 @@  pthread-compat-wrappers = \
 libpthread-routines = nptl-init nptlfreeres vars events version pt-interp \
 		      pthread_create pthread_exit pthread_detach \
 		      pthread_join pthread_tryjoin pthread_timedjoin \
-		      pthread_join_common \
+		      pthread_clockjoin pthread_join_common \
 		      compat-pthread_self pthread_equal pthread_yield \
 		      pthread_getconcurrency pthread_setconcurrency \
 		      pthread_getschedparam pthread_setschedparam \
@@ -190,6 +190,7 @@  CFLAGS-forward.c += -fexceptions
 CFLAGS-pthread_testcancel.c += -fexceptions
 CFLAGS-pthread_join.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-pthread_timedjoin.c += -fexceptions -fasynchronous-unwind-tables
+CFLAGS-pthread_clockjoin.c += -fexceptions -fasynchronous-unwind-tables
 CFLAGS-pthread_once.c += $(uses-callbacks) -fexceptions \
 			-fasynchronous-unwind-tables
 CFLAGS-pthread_cond_wait.c += -fexceptions -fasynchronous-unwind-tables
@@ -274,7 +275,7 @@  tests = tst-attr1 tst-attr2 tst-attr3 tst-default-attr \
 	tst-kill1 tst-kill2 tst-kill3 tst-kill4 tst-kill5 tst-kill6 \
 	tst-raise1 \
 	tst-join1 tst-join2 tst-join3 tst-join4 tst-join5 tst-join6 tst-join7 \
-	tst-join8 tst-join9 \
+	tst-join8 tst-join9 tst-join10 tst-join11 tst-join12 tst-join13 \
 	tst-detach1 \
 	tst-eintr2 tst-eintr3 tst-eintr4 tst-eintr5 \
 	tst-tsd1 tst-tsd2 tst-tsd3 tst-tsd4 tst-tsd5 tst-tsd6 \
diff --git a/nptl/Versions b/nptl/Versions
index e903b84..443d4fb 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -281,6 +281,7 @@  libpthread {
     sem_clockwait; pthread_cond_clockwait;
     pthread_rwlock_clockrdlock; pthread_rwlock_clockwrlock;
     pthread_mutex_clocklock;
+    pthread_clockjoin_np;
   }
 
   GLIBC_PRIVATE {
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
index d80662a..ea7b5bf 100644
--- a/nptl/pthreadP.h
+++ b/nptl/pthreadP.h
@@ -475,7 +475,8 @@  extern int __pthread_setcanceltype (int type, int *oldtype);
 extern int __pthread_enable_asynccancel (void) attribute_hidden;
 extern void __pthread_disable_asynccancel (int oldtype) attribute_hidden;
 extern void __pthread_testcancel (void);
-extern int __pthread_timedjoin_ex (pthread_t, void **, const struct timespec *,
+extern int __pthread_clockjoin_ex (pthread_t, void **,
+                                   clockid_t, const struct timespec *,
 				   bool);
 
 #if IS_IN (libpthread)
@@ -495,7 +496,7 @@  hidden_proto (__pthread_setcancelstate)
 hidden_proto (__pthread_testcancel)
 hidden_proto (__pthread_mutexattr_init)
 hidden_proto (__pthread_mutexattr_settype)
-hidden_proto (__pthread_timedjoin_ex)
+hidden_proto (__pthread_clockjoin_ex)
 #endif
 
 extern int __pthread_cond_broadcast_2_0 (pthread_cond_2_0_t *cond);
diff --git a/nptl/pthread_join.c b/nptl/pthread_join.c
index 379ddc8..0fb0aaa 100644
--- a/nptl/pthread_join.c
+++ b/nptl/pthread_join.c
@@ -21,6 +21,6 @@ 
 int
 __pthread_join (pthread_t threadid, void **thread_return)
 {
-  return __pthread_timedjoin_ex (threadid, thread_return, NULL, true);
+  return __pthread_clockjoin_ex (threadid, thread_return, 0, NULL, true);
 }
 weak_alias (__pthread_join, pthread_join)
diff --git a/nptl/pthread_join_common.c b/nptl/pthread_join_common.c
index 5224ee2..c3538f9 100644
--- a/nptl/pthread_join_common.c
+++ b/nptl/pthread_join_common.c
@@ -36,7 +36,7 @@  cleanup (void *arg)
    afterwards.  The kernel up to version 3.16.3 does not use the private futex
    operations for futex wake-up when the clone terminates.  */
 static int
-timedwait_tid (pid_t *tidp, const struct timespec *abstime)
+clockwait_tid (pid_t *tidp, clockid_t clockid, const struct timespec *abstime)
 {
   pid_t tid;
 
@@ -46,15 +46,17 @@  timedwait_tid (pid_t *tidp, const struct timespec *abstime)
   /* Repeat until thread terminated.  */
   while ((tid = *tidp) != 0)
     {
-      struct timeval tv;
+      struct timespec ts;
       struct timespec rt;
 
-      /* Get the current time.  */
-      __gettimeofday (&tv, NULL);
+      /* Get the current time. This can only fail if clockid is
+         invalid. */
+      if (__glibc_unlikely (__clock_gettime (clockid, &ts)))
+        return EINVAL;
 
       /* Compute relative timeout.  */
-      rt.tv_sec = abstime->tv_sec - tv.tv_sec;
-      rt.tv_nsec = abstime->tv_nsec - tv.tv_usec * 1000;
+      rt.tv_sec = abstime->tv_sec - ts.tv_sec;
+      rt.tv_nsec = abstime->tv_nsec - ts.tv_nsec;
       if (rt.tv_nsec < 0)
         {
           rt.tv_nsec += 1000000000;
@@ -77,7 +79,8 @@  timedwait_tid (pid_t *tidp, const struct timespec *abstime)
 }
 
 int
-__pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
+__pthread_clockjoin_ex (pthread_t threadid, void **thread_return,
+                        clockid_t clockid,
 			const struct timespec *abstime, bool block)
 {
   struct pthread *pd = (struct pthread *) threadid;
@@ -122,7 +125,7 @@  __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
 
   /* BLOCK waits either indefinitely or based on an absolute time.  POSIX also
      states a cancellation point shall occur for pthread_join, and we use the
-     same rationale for posix_timedjoin_np.  Both timedwait_tid and the futex
+     same rationale for posix_timedjoin_np.  Both clockwait_tid and the futex
      call use the cancellable variant.  */
   if (block)
     {
@@ -132,7 +135,7 @@  __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
       pthread_cleanup_push (cleanup, &pd->joinid);
 
       if (abstime != NULL)
-	result = timedwait_tid (&pd->tid, abstime);
+	result = clockwait_tid (&pd->tid, clockid, abstime);
       else
 	{
 	  pid_t tid;
@@ -165,4 +168,4 @@  __pthread_timedjoin_ex (pthread_t threadid, void **thread_return,
 
   return result;
 }
-hidden_def (__pthread_timedjoin_ex)
+hidden_def (__pthread_clockjoin_ex)
diff --git a/nptl/pthread_timedjoin.c b/nptl/pthread_timedjoin.c
index 323c0ff..55a0cb9 100644
--- a/nptl/pthread_timedjoin.c
+++ b/nptl/pthread_timedjoin.c
@@ -22,6 +22,7 @@  int
 __pthread_timedjoin_np (pthread_t threadid, void **thread_return,
 			const struct timespec *abstime)
 {
-  return __pthread_timedjoin_ex (threadid, thread_return, abstime, true);
+  return __pthread_clockjoin_ex (threadid, thread_return,
+                                 CLOCK_REALTIME, abstime, true);
 }
 weak_alias (__pthread_timedjoin_np, pthread_timedjoin_np)
diff --git a/nptl/pthread_tryjoin.c b/nptl/pthread_tryjoin.c
index 7dbf228..d76c4a6 100644
--- a/nptl/pthread_tryjoin.c
+++ b/nptl/pthread_tryjoin.c
@@ -28,5 +28,5 @@  pthread_tryjoin_np (pthread_t threadid, void **thread_return)
 
   /* If pd->tid == 0 then lll_wait_tid will not block on futex
      operation.  */
-  return __pthread_timedjoin_ex (threadid, thread_return, NULL, false);
+  return __pthread_clockjoin_ex (threadid, thread_return, 0, NULL, false);
 }
diff --git a/nptl/thrd_join.c b/nptl/thrd_join.c
index b3df236..64b0d08 100644
--- a/nptl/thrd_join.c
+++ b/nptl/thrd_join.c
@@ -22,7 +22,7 @@  int
 thrd_join (thrd_t thr, int *res)
 {
   void *pthread_res;
-  int err_code = __pthread_timedjoin_ex (thr, &pthread_res, NULL, true);
+  int err_code = __pthread_clockjoin_ex (thr, &pthread_res, 0, NULL, true);
   if (res)
    *res = (int) (uintptr_t) pthread_res;
 
diff --git a/nptl/tst-join10.c b/nptl/tst-join10.c
new file mode 100644
index 0000000..a222dd1
--- /dev/null
+++ b/nptl/tst-join10.c
@@ -0,0 +1,20 @@ 
+/* Check if pthread_clockjoin_np is a cancellation entrypoint.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_PTHREAD_CLOCKJOIN_NP_REALTIME 1
+#include <nptl/tst-join5.c>
diff --git a/nptl/tst-join11.c b/nptl/tst-join11.c
new file mode 100644
index 0000000..341588a
--- /dev/null
+++ b/nptl/tst-join11.c
@@ -0,0 +1,21 @@ 
+/* Check if pthread_clockjoin_np is a cancellation entrypoint.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_PTHREAD_CLOCKJOIN_NP_REALTIME 1
+#define WAIT_IN_CHILD 1
+#include <nptl/tst-join5.c>
diff --git a/nptl/tst-join12.c b/nptl/tst-join12.c
new file mode 100644
index 0000000..44592dc
--- /dev/null
+++ b/nptl/tst-join12.c
@@ -0,0 +1,20 @@ 
+/* Check if pthread_clockjoin_np is a cancellation entrypoint.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC 1
+#include <nptl/tst-join5.c>
diff --git a/nptl/tst-join13.c b/nptl/tst-join13.c
new file mode 100644
index 0000000..d4e49d5
--- /dev/null
+++ b/nptl/tst-join13.c
@@ -0,0 +1,21 @@ 
+/* Check if pthread_clockjoin_np is a cancellation entrypoint.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC 1
+#define WAIT_IN_CHILD 1
+#include <nptl/tst-join5.c>
diff --git a/nptl/tst-join3.c b/nptl/tst-join3.c
index 460b862..2471de0 100644
--- a/nptl/tst-join3.c
+++ b/nptl/tst-join3.c
@@ -28,6 +28,8 @@ 
 #include <support/xtime.h>
 
 
+#define CLOCK_USE_TIMEDJOIN (-1)
+
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
 
@@ -35,19 +37,23 @@  static void *
 tf (void *arg)
 {
   xpthread_mutex_lock (&lock);
+  xpthread_mutex_unlock (&lock);
 
   return (void *) 42l;
 }
 
 
 static int
-do_test (void)
+do_test_clock (clockid_t clockid)
 {
+  const clockid_t clockid_for_get =
+    (clockid == CLOCK_USE_TIMEDJOIN) ? CLOCK_REALTIME : clockid;
+
   xpthread_mutex_lock (&lock);
   pthread_t th = xpthread_create (NULL, tf, NULL);
 
   void *status;
-  struct timespec timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+  struct timespec timeout = timespec_add (xclock_now (clockid_for_get),
                                           make_timespec (0, 200000000));
 
   int val = pthread_timedjoin_np (th, &status, &timeout);
@@ -57,10 +63,13 @@  do_test (void)
 
   while (1)
     {
-      timeout = timespec_add (xclock_now (CLOCK_REALTIME),
+      timeout = timespec_add (xclock_now (clockid_for_get),
                               make_timespec (0, 200000000));
 
-      val = pthread_timedjoin_np (th, &status, &timeout);
+      if (clockid == CLOCK_USE_TIMEDJOIN)
+        val = pthread_timedjoin_np (th, &status, &timeout);
+      else
+        val = pthread_clockjoin_np (th, &status, clockid, &timeout);
       if (val == 0)
 	break;
 
@@ -73,4 +82,13 @@  do_test (void)
   return 0;
 }
 
+static int
+do_test (void)
+{
+  do_test_clock (CLOCK_USE_TIMEDJOIN);
+  do_test_clock (CLOCK_REALTIME);
+  do_test_clock (CLOCK_MONOTONIC);
+  return 0;
+}
+
 #include <support/test-driver.c>
diff --git a/nptl/tst-join5.c b/nptl/tst-join5.c
index 39f74dc..dd098fd 100644
--- a/nptl/tst-join5.c
+++ b/nptl/tst-join5.c
@@ -24,7 +24,9 @@ 
 #include <unistd.h>
 
 #include <support/check.h>
+#include <support/timespec.h>
 #include <support/xthread.h>
+#include <support/xtime.h>
 
 static void
 wait_code (void)
@@ -42,12 +44,18 @@  static pthread_barrier_t b;
 static int
 thread_join (pthread_t thread, void **retval)
 {
-#ifdef USE_PTHREAD_TIMEDJOIN_NP
-  struct timespec tv;
-  TEST_COMPARE (clock_gettime (CLOCK_REALTIME, &tv), 0);
-  /* Arbitrary large timeout to make it act as pthread_join.  */
-  tv.tv_sec += 1000;
-  return pthread_timedjoin_np ((pthread_t) thread, retval, &tv);
+#if defined USE_PTHREAD_TIMEDJOIN_NP
+  const struct timespec ts = timespec_add (xclock_now (CLOCK_REALTIME),
+                                           make_timespec (1000, 0));
+  return pthread_timedjoin_np ((pthread_t) thread, retval, &ts);
+#elif defined USE_PTHREAD_CLOCKJOIN_NP_REALTIME
+  const struct timespec ts = timespec_add (xclock_now (CLOCK_REALTIME),
+                                           make_timespec (1000, 0));
+  return pthread_clockjoin_np ((pthread_t) thread, retval, CLOCK_REALTIME, &ts);
+#elif defined USE_PTHREAD_CLOCKJOIN_NP_MONOTONIC
+  const struct timespec ts = timespec_add (xclock_now (CLOCK_MONOTONIC),
+                                           make_timespec (1000, 0));
+  return pthread_clockjoin_np ((pthread_t) thread, retval, CLOCK_MONOTONIC, &ts);
 #else
   return pthread_join ((pthread_t) thread, retval);
 #endif
diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h
index a767d6f..00d996c 100644
--- a/sysdeps/nptl/pthread.h
+++ b/sysdeps/nptl/pthread.h
@@ -263,6 +263,17 @@  extern int pthread_tryjoin_np (pthread_t __th, void **__thread_return) __THROW;
    __THROW.  */
 extern int pthread_timedjoin_np (pthread_t __th, void **__thread_return,
 				 const struct timespec *__abstime);
+
+/* Make calling thread wait for termination of the thread TH, but only
+   until TIMEOUT measured against the clock specified by CLOCKID.  The
+   exit status of the thread is stored in *THREAD_RETURN, if
+   THREAD_RETURN is not NULL.
+
+   This function is a cancellation point and therefore not marked with
+   __THROW.  */
+extern int pthread_clockjoin_np (pthread_t __th, void **__thread_return,
+                                 clockid_t clockid,
+				 const struct timespec *__abstime);
 #endif
 
 /* Indicate that the thread TH is never to be joined with PTHREAD_JOIN.
diff --git a/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist b/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist
index 69f48bf..8b4c928 100644
--- a/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/aarch64/libpthread.abilist
@@ -243,6 +243,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/alpha/libpthread.abilist b/sysdeps/unix/sysv/linux/alpha/libpthread.abilist
index 7aa6416..1637215 100644
--- a/sysdeps/unix/sysv/linux/alpha/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/alpha/libpthread.abilist
@@ -255,6 +255,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/arm/libpthread.abilist b/sysdeps/unix/sysv/linux/arm/libpthread.abilist
index 3d2287b..d5f393a 100644
--- a/sysdeps/unix/sysv/linux/arm/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/arm/libpthread.abilist
@@ -27,6 +27,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/csky/libpthread.abilist b/sysdeps/unix/sysv/linux/csky/libpthread.abilist
index 52373fc..47f3ff2 100644
--- a/sysdeps/unix/sysv/linux/csky/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/csky/libpthread.abilist
@@ -233,6 +233,7 @@  GLIBC_2.29 tss_set F
 GLIBC_2.29 wait F
 GLIBC_2.29 waitpid F
 GLIBC_2.29 write F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/hppa/libpthread.abilist b/sysdeps/unix/sysv/linux/hppa/libpthread.abilist
index d11e150..6e39a7d 100644
--- a/sysdeps/unix/sysv/linux/hppa/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/hppa/libpthread.abilist
@@ -245,6 +245,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/i386/libpthread.abilist b/sysdeps/unix/sysv/linux/i386/libpthread.abilist
index 1b385ca..40a3963 100644
--- a/sysdeps/unix/sysv/linux/i386/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/i386/libpthread.abilist
@@ -253,6 +253,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/ia64/libpthread.abilist b/sysdeps/unix/sysv/linux/ia64/libpthread.abilist
index bde9948..fae4241 100644
--- a/sysdeps/unix/sysv/linux/ia64/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/ia64/libpthread.abilist
@@ -247,6 +247,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
index 3d2287b..d5f393a 100644
--- a/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist
@@ -27,6 +27,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
index 1b385ca..40a3963 100644
--- a/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist
@@ -253,6 +253,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist b/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
index f0365f3..6f9e18a 100644
--- a/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/microblaze/libpthread.abilist
@@ -243,6 +243,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist b/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
index b1dff8e..4db6c83 100644
--- a/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist
@@ -255,6 +255,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist b/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
index b1dff8e..4db6c83 100644
--- a/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist
@@ -255,6 +255,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/nios2/libpthread.abilist b/sysdeps/unix/sysv/linux/nios2/libpthread.abilist
index 0150ea3..99a75b6 100644
--- a/sysdeps/unix/sysv/linux/nios2/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/nios2/libpthread.abilist
@@ -241,6 +241,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
index 9e71e17..9316ec7 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist
@@ -255,6 +255,7 @@  GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
 GLIBC_2.3.4 siglongjmp F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
index 393ec87..564abdc 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist
@@ -246,6 +246,7 @@  GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
 GLIBC_2.3.4 siglongjmp F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
index 69f48bf..8b4c928 100644
--- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist
@@ -243,6 +243,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
index 7dab4e5..df81182 100644
--- a/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist
@@ -235,6 +235,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
index 7db2a0c..ebe8962 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist
@@ -255,6 +255,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
index 7c10bb2..91f4857 100644
--- a/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist
@@ -247,6 +247,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/sh/libpthread.abilist b/sysdeps/unix/sysv/linux/sh/libpthread.abilist
index d11e150..6e39a7d 100644
--- a/sysdeps/unix/sysv/linux/sh/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/sh/libpthread.abilist
@@ -245,6 +245,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
index 7aa6416..1637215 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist
@@ -255,6 +255,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
index bde9948..fae4241 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist
@@ -247,6 +247,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
index c5ecb12..72bdb17 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist
@@ -245,6 +245,7 @@  GLIBC_2.3.4 pthread_attr_setaffinity_np F
 GLIBC_2.3.4 pthread_getaffinity_np F
 GLIBC_2.3.4 pthread_setaffinity_np F
 GLIBC_2.3.4 pthread_setschedprio F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
index a7ff3fb..b738283 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist
@@ -243,6 +243,7 @@  GLIBC_2.28 tss_create F
 GLIBC_2.28 tss_delete F
 GLIBC_2.28 tss_get F
 GLIBC_2.28 tss_set F
+GLIBC_2.30 pthread_clockjoin_np F
 GLIBC_2.30 pthread_cond_clockwait F
 GLIBC_2.30 pthread_mutex_clocklock F
 GLIBC_2.30 pthread_rwlock_clockrdlock F