[LTP] [PATCH v2] pthread_detach_1-2: Fix failure on modern glibc
Martin Doucha
mdoucha@suse.cz
Thu Jun 11 17:33:31 CEST 2026
Hi,
this looks like trying to hide a glibc bug to me. I've looked at both
the POSIX standard and Linux man pages and there is no mention that
already exited threads may be left joinable. I think we should report
this as a bug and wait for response from glibc maintainers.
On 5/9/26 09:39, Wei Gao via ltp wrote:
> Latest test in our openqa setup (Linux 7.1-rc2, Glibc 2.43) show following error:
> Test FAILED: We were able to join a detached thread.
>
> This is triggered by glibc commit 5da15b15adab661c80e373b6af89be0b5fa5b3ad
> ("nptl: Do not use pthread set_tid_address as state synchronization (BZ #19951)").
>
> New logic remove the logic of check whether valid thread handle in __pthread_clockjoin_ex().
> - /* Make sure the descriptor is valid. */
> - if (INVALID_NOT_TERMINATED_TD_P (pd))
> - /* Not a valid thread handle. */
> - return ESRCH;
>
> So add a second synchronization semaphore to ensure the child thread remains
> alive until the main thread has completed its checks. This forces glibc
> to see the THREAD_STATE_DETACHED status and correctly return EINVAL.
>
> Signed-off-by: Wei Gao <wegao@suse.com>
> ---
> v1->v2:
> - Update commit message for root cause detail
>
> .../interfaces/pthread_detach/1-2.c | 25 +++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
> index dc5ed39d3..1a9650f49 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
> @@ -92,6 +92,7 @@
> /********************************************************************************************/
>
> static unsigned int sc;
> +static sem_t sem_exit;
>
> static void *threaded(void *arg)
> {
> @@ -113,6 +114,15 @@ static void *threaded(void *arg)
> UNRESOLVED(errno, "Failed to post the semaphore");
> }
>
> + /* Wait for the main thread to allow exit */
> + do {
> + ret = sem_wait(&sem_exit);
> + }
> + while ((ret == -1) && (errno == EINTR));
> + if (ret == -1) {
> + UNRESOLVED(errno, "Failed to wait for the exit semaphore");
> + }
> +
> return arg;
> }
>
> @@ -125,6 +135,11 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
>
> scenar_init();
>
> + ret = sem_init(&sem_exit, 0, 0);
> + if (ret != 0) {
> + UNRESOLVED(errno, "Failed to init the exit semaphore");
> + }
> +
> for (sc = 0; sc < NSCENAR; sc++) {
> #if VERBOSE > 0
> output("-----\n");
> @@ -202,11 +217,21 @@ int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
> ("We were able to join a detached thread.");
> }
>
> + /* Allow the thread to exit */
> + do {
> + ret = sem_post(&sem_exit);
> + }
> + while ((ret == -1) && (errno == EINTR));
> + if (ret == -1) {
> + UNRESOLVED(errno, "Failed to post the exit semaphore");
> + }
> +
> /* Let the thread an additionnal row to cleanup */
> sched_yield();
> }
> }
>
> + sem_destroy(&sem_exit);
> scenar_fini();
> #if VERBOSE > 0
> output("-----\n");
--
Martin Doucha mdoucha@suse.cz
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic
More information about the ltp
mailing list