1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

nptl: Use exit_lock when accessing TID on pthread_getaffinity_np

Also return EINVAL if the thread is already terminated at the time of
the call.  This is slight better than returning the calling thread
affinity (current behaviour), since the thread lifetime is defined.

Checked on x86_64-linux-gnu.
This commit is contained in:
Adhemerval Zanella
2021-08-23 13:51:54 -03:00
parent e4585134ca
commit a75cd1e3af
3 changed files with 71 additions and 11 deletions

View File

@@ -217,6 +217,7 @@ tests += \
tst-pt-vfork1 \
tst-pt-vfork2 \
tst-pthread-exit-signal \
tst-pthread-exited \
tst-pthread-mutexattr \
tst-pthread-mutexattr-2 \
tst-pthread-raise-blocked-self \

View File

@@ -0,0 +1,51 @@
/* Test pthread interface which should return ESRCH when issues along
with a terminated pthread_t.
Copyright (C) 2025 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
<https://www.gnu.org/licenses/>. */
#include <errno.h>
#include <signal.h>
#include <stddef.h>
#include <support/check.h>
#include <support/support.h>
#include <support/xthread.h>
static void *
noop_thread (void *closure)
{
return NULL;
}
static int
do_test (void)
{
pthread_t thr = xpthread_create (NULL, noop_thread, NULL);
support_wait_for_thread_exit ();
{
cpu_set_t cpuset;
int r = pthread_getaffinity_np (thr, sizeof (cpuset), &cpuset);
TEST_COMPARE (r, EINVAL);
}
xpthread_join (thr);
return 0;
}
#include <support/test-driver.c>