[PATCH] nptl: Fix nptl/tst-cancel31 fail sometimes
Carlos O'Donell
carlos@redhat.com
Tue Mar 24 16:45:02 GMT 2026
On 3/24/26 3:48 AM, mengqinggang wrote:
> tst-cancel31 fail on la32 qemu-system with a single-core
> system sometimes.
LGTM. Pushed.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> IF the test and a infinite loop run on a same x86_64 core,
> the test also fail sometimes.
> taskset -c 0 make test t=nptl/tst-cancel31
> taskset -c 0 ./a.out (a.out is a infinite loop)
>
> After writeopener thread opens the file, it may switch to
> main thread and find redundant files.
Agreed.
writeopener
fd = open (arg, O_WRONLY);
main
support_descriptors_check (descrs);
Fails because writeopener had an open descriptor
xclose (fd);
The test fails if main executes between the open and close
of writeopener.
>
> pthread_cancel and pthread_join writeopener thread
> before support_descriptors_check.
> ---
> nptl/tst-cancel31.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/nptl/tst-cancel31.c b/nptl/tst-cancel31.c
> index e9ffef3b41..8909879ff4 100644
> --- a/nptl/tst-cancel31.c
> +++ b/nptl/tst-cancel31.c
> @@ -43,7 +43,9 @@ writeopener (void *arg)
> for (;;)
> {
> fd = open (arg, O_WRONLY);
> + pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, 0);
> xclose (fd);
> + pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, 0);
OK.
> }
> return NULL;
> }
> @@ -74,7 +76,7 @@ do_test (void)
>
> srand (1);
>
> - xpthread_create (NULL, writeopener, name);
> + pthread_t tw = xpthread_create (NULL, writeopener, name);
> for (int i = 0; i < iter_count; i++)
> {
> pthread_t td = xpthread_create (NULL, leaker, name);
> @@ -88,6 +90,9 @@ do_test (void)
> xpthread_join (td);
> }
>
> + pthread_cancel (tw);
> + xpthread_join (tw);
OK.
> +
> support_descriptors_check (descrs);
>
> support_descriptors_free (descrs);
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list