Home | History | Annotate | only in /src/tests/lib/libpthread
History log of /src/tests/lib/libpthread
RevisionDateAuthorComments
 1.22 18-Oct-2025  riastradh tests/lib/libpthread: Fix tests in subdirectory.

Need to use TESTS_SUBDIRS for this, not SUBDIR. Avoid the extra
nesting level while here; can make the library be a subdirectory of
the directory where the tests live.

PR lib/59685: libcrypto should not depend on libpthread
 1.21 06-Oct-2025  leot libpthread: append to SUBDIR instead of overwrite it

Noticed and from <riastradh>, thanks!

PR lib/59685: libcrypto should not depend on libpthread
 1.20 06-Oct-2025  riastradh libpthread: Test pthread stubs in threaded vs non-threaded programs.

PR lib/59685: libcrypto should not depend on libpthread
 1.19 08-Apr-2025  riastradh tests/lib/libpthread/t_compat_cancel: Make linker warnings non-fatal.

We will get warnings like:

/home/riastradh/netbsd/current/src/tests/lib/libpthread/t_compat_cancel.c:233: warning: warning: reference to compatibility sigsuspend(); include <signal.h> for correct reference

This is intended -- t_compat_cancel deliberately uses the compat
symbols, not the modern symbols, in order to test the compat symbols.

Fixes clang build because bsd.sys.mk enables -Wl,--fatal-warnings in
LDFLAGS by default.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.18 05-Apr-2025  riastradh Add tests for compat functions as cancellation points.

While here, test kevent too.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.17 31-Mar-2025  riastradh pthread_cancel(3): Add some automatic tests.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
 1.16 24-Nov-2023  riastradh branches: 1.16.2;
pthread: Add tests for pthread user stack allocation.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.15 21-Jun-2020  lukem branches: 1.15.6;
fix build of h_thread_local_dtor.cpp
 1.14 24-Apr-2019  kamil branches: 1.14.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.13 11-Jul-2017  joerg branches: 1.13.6;
Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.

If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.

Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
 1.12 30-Oct-2016  kamil branches: 1.12.6;
Add new test t_timedmutex

This test is a clone on t_mutex with additional two tests for timed-mutex
specific block.

All simple-mutex (not with the timed property according to the C11 wording)
specific tests are covered by pthread_mutex_timedlock(3) with parameter
ts_lengthy of sufficiently large tv_sec value (right now UINT16_MAX). If,
a test will hang, it won't wait UINT16_MAX seconds, but will be terminated
within the default timeout for ATF tests (right now 300 [sec] in my
NetBSD/amd64 setup).

This test was inspired by a classic selflock test failure of
pthread_mutex_timedlock(3) of the following form:

#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
pthread_mutex_t mtx;
struct timespec ts;

ts.tv_sec = 0;
ts.tv_nsec = 1000;
printf("ts{.tv_sec = %d, .tv_nsec=%ld}\n", ts.tv_sec, ts.tv_nsec);
fflush(stdout);

printf("mtx_init\n");
assert(pthread_mutex_init(&mtx, NULL) == 0);

printf("mtx_lock\n");
assert(pthread_mutex_lock(&mtx) == 0);

printf("mtx_timedlock\n");
assert(pthread_mutex_timedlock(&mtx, &ts) == ETIMEDOUT);

printf("mtx_unlock\n");
assert(pthread_mutex_unlock(&mtx) == 0);

printf("mtx_destroy\n");
assert(pthread_mutex_destroy(&mtx) == 0);

return 0;
}

Current NetBSD implementation wrongly hangs on this test.

The issue was detected during development of the C11 portable threads.

My local tests in chroot presents that the are further issues:

t_timedmutex (21/25): 10 test cases
mutex1: [0.001142s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:75: *param != 20
mutex2: [0.261499s] Passed.
mutex3: [0.261496s] Passed.
mutex4: [0.001204s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:265: pthread_mutex_timedlock(&mutex, &ts_lengthy): Connection timed out
mutex5: [0.001235s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:337: pthread_mutex_timedlock(&mutex5, &ts_lengthy): Connection timed out
mutex6: [21.218497s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:512: start != 1
mutexattr1: [0.001328s] Passed.
mutexattr2: [0.001175s] Passed.
timedmutex1: [301.119397s] Failed: Test case timed out after 300 seconds
timedmutex2: [301.123081s] Failed: Test case timed out after 300 seconds
[623.990659s]

I'm also receiveing the same failure in the mutex6 test in t_mutex, so
there might be a false positives due to local chroot(8) issues.

Commit approved by <christos>.
 1.11 12-Apr-2013  christos branches: 1.11.10;
loosen the test only for qemu.
 1.10 28-Mar-2013  christos Add pthread_cond_timedwait(3) test from PR/47703
 1.9 21-Mar-2013  christos new dlopen tests for libpthread from manu@
 1.8 12-Sep-2012  manu branches: 1.8.2;
setcontext() used to be incompatible with -lpthread since it affected
the TLS pointer, therefore wrecking the pthread environement.

Some ports had _UC_TLSBASE flag or equivalent (_UC_UNIQUE on alpha)
that controlled whether setcontext() would change the TLS pointer.
This change let libpthread override setcontext() with its own version
that unsets _UC_TLSBASE, enabling safe usage of setcontext() with
-lpthread.

We also have the following required changes here:
- rename alpha's _UC_UNIQUE into _UC_TLSBASE
- add _UC_TLSBASE definition in header file for all ports
(powerpc, sh3, sparc and sparc64 lack the implementation for now)
- introduce a libc stub that can be overriden for setcontext()
- modify MD libcs swapcontext() implementations so that they use the
setcontext() libc stub instead of doing a plain system call.

While we are there:
- document various MD _UC_* flags in header file
- add libc and libpthread tests for swapcontext() behavior
(hopefully helpful to spot MD problems introduced with this change)

Future work:
- Deciding whether kernel support or _UC_TLSBASE should be added for
powerpc, sh3, sparc and sparc64 is left to portmasters
sparc64

Approved by core@
 1.7 06-Apr-2011  jruoho branches: 1.7.4;
As per PR lib/44818, remove 'lib/libpthread/t_status'. It takes two minutes
to rewrite this properly if someone misses this.
 1.6 24-Mar-2011  jruoho A dummy conformance-test for pthread_detach(3). I will extend this later.
 1.5 24-Mar-2011  jruoho A dummy conformance-test of pthread_equal(3).
 1.4 08-Dec-2010  joerg Link t_fpu against libm if the compiler doesn't want to inline sin/cos.
 1.3 30-Nov-2010  joerg Test alignment of constructor / destructor calls as well as the stack
of new threads. Currently implement for i386 and AMD64.
 1.2 28-Jul-2010  jruoho Add a simple test for pthread_join(3).
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.7.4.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.7.4.1 30-Oct-2012  yamt sync with head
 1.8.2.1 23-Jun-2013  tls resync from head
 1.11.10.1 04-Nov-2016  pgoyette Sync with HEAD
 1.12.6.2 09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1924):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.12.6.1 29-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #127):
tests/libexec/ld.elf_so/h_thread_local_dtor.c: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmeb/c++config.h: revision 1.17
lib/libc/stdlib/atexit.h: file removal
lib/libc/stdlib/exit.c: revision 1.16
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc64/c++config.h: revision 1.8
lib/libc/stdlib/exit.c: revision 1.17
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.178
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3el/c++config.h: revision 1.21
distrib/sets/lists/debug/shl.mi: revision 1.179
distrib/sets/lists/debug/mi: revision 1.219
lib/libpthread/pthread.c: revision 1.150
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7/c++config.h: revision 1.14
libexec/ld.elf_so/symbols.map: revision 1.2
include/dlfcn.h: revision 1.25
external/gpl3/gcc/lib/libstdc++-v3/arch/arm/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/x86_64/c++config.h: revision 1.23
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64el/c++config.h: revision 1.18
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earm/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/mipsel/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/ia64/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhf/c++config.h: revision 1.17
distrib/sets/lists/tests/mi: revision 1.755
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/i386/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/vax/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/armeb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc/c++config.h: revision 1.20
lib/libc/dlfcn/dlfcn_elf.c: revision 1.14
tests/libexec/ld.elf_so/t_thread_local_dtor.sh: revision 1.1
tests/lib/libpthread/t_thread_local_dtor.sh: revision 1.1
lib/libc/stdlib/Makefile.inc: revision 1.93
lib/libc/include/atexit.h: revision 1.1
lib/libc/include/atexit.h: revision 1.2
external/gpl3/gcc/lib/libstdc++-v3/arch/m68k/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.180
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc64/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hfeb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/hppa/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hfeb/c++config.h: revision 1.14
lib/libc/stdlib/cxa_thread_atexit.c: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/h_helper_dso3.cpp: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/Makefile: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv64/c++config.h: revision 1.5
libexec/ld.elf_so/rtld.c: revision 1.185
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv32/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/m68000/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/mipseb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/coldfire/c++config.h: revision 1.12
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhfeb/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/alpha/c++config.h: revision 1.19
tests/libexec/ld.elf_so/Makefile: revision 1.9
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7eb/c++config.h: revision 1.14
tests/lib/libpthread/h_thread_local_dtor.cpp: revision 1.1
distrib/sets/lists/tests/shl.mi: revision 1.11
tests/lib/libpthread/Makefile: revision 1.13
libexec/ld.elf_so/rtld.h: revision 1.129
external/gpl3/gcc/lib/libstdc++-v3/arch/or1k/c++config.h: revision 1.6
Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.
If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.
Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
Fix filename of new debug file
Add misising DEBUGLIB file
Avoid common declaration.
Drop TLS variant checks, emutls is enough for VAX and Sun2.
 1.13.6.1 10-Jun-2019  christos Sync with HEAD
 1.14.2.1 09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1775):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.15.6.1 28-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #478):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.16.2.1 02-Aug-2025  perseant Sync with HEAD
 1.1 05-Apr-2025  riastradh branches: 1.1.4;
Add tests for compat functions as cancellation points.

While here, test kevent too.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 05-Apr-2025  perseant file cancelpoint.h was added on branch perseant-exfatfs on 2025-08-02 05:58:09 +0000
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.3 16-Jan-2017  christos beware of your shadow
 1.2 30-Oct-2016  kamil branches: 1.2.2;
Add new test t_timedmutex

This test is a clone on t_mutex with additional two tests for timed-mutex
specific block.

All simple-mutex (not with the timed property according to the C11 wording)
specific tests are covered by pthread_mutex_timedlock(3) with parameter
ts_lengthy of sufficiently large tv_sec value (right now UINT16_MAX). If,
a test will hang, it won't wait UINT16_MAX seconds, but will be terminated
within the default timeout for ATF tests (right now 300 [sec] in my
NetBSD/amd64 setup).

This test was inspired by a classic selflock test failure of
pthread_mutex_timedlock(3) of the following form:

#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
pthread_mutex_t mtx;
struct timespec ts;

ts.tv_sec = 0;
ts.tv_nsec = 1000;
printf("ts{.tv_sec = %d, .tv_nsec=%ld}\n", ts.tv_sec, ts.tv_nsec);
fflush(stdout);

printf("mtx_init\n");
assert(pthread_mutex_init(&mtx, NULL) == 0);

printf("mtx_lock\n");
assert(pthread_mutex_lock(&mtx) == 0);

printf("mtx_timedlock\n");
assert(pthread_mutex_timedlock(&mtx, &ts) == ETIMEDOUT);

printf("mtx_unlock\n");
assert(pthread_mutex_unlock(&mtx) == 0);

printf("mtx_destroy\n");
assert(pthread_mutex_destroy(&mtx) == 0);

return 0;
}

Current NetBSD implementation wrongly hangs on this test.

The issue was detected during development of the C11 portable threads.

My local tests in chroot presents that the are further issues:

t_timedmutex (21/25): 10 test cases
mutex1: [0.001142s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:75: *param != 20
mutex2: [0.261499s] Passed.
mutex3: [0.261496s] Passed.
mutex4: [0.001204s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:265: pthread_mutex_timedlock(&mutex, &ts_lengthy): Connection timed out
mutex5: [0.001235s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:337: pthread_mutex_timedlock(&mutex5, &ts_lengthy): Connection timed out
mutex6: [21.218497s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:512: start != 1
mutexattr1: [0.001328s] Passed.
mutexattr2: [0.001175s] Passed.
timedmutex1: [301.119397s] Failed: Test case timed out after 300 seconds
timedmutex2: [301.123081s] Failed: Test case timed out after 300 seconds
[623.990659s]

I'm also receiveing the same failure in the mutex6 test in t_mutex, so
there might be a false positives due to local chroot(8) issues.

Commit approved by <christos>.
 1.1 16-Jul-2010  jmmv branches: 1.1.28;
Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1.28.2 20-Mar-2017  pgoyette Sync with HEAD
 1.1.28.1 04-Nov-2016  pgoyette Sync with HEAD
 1.2.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.3 06-Mar-2019  christos add joins
 1.2 03-Nov-2010  christos branches: 1.2.46;
add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2.46.1 10-Jun-2019  christos Sync with HEAD
 1.1 11-Jul-2017  joerg branches: 1.1.4;
Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.

If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.

Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
 1.1.4.2 29-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #127):
tests/libexec/ld.elf_so/h_thread_local_dtor.c: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmeb/c++config.h: revision 1.17
lib/libc/stdlib/atexit.h: file removal
lib/libc/stdlib/exit.c: revision 1.16
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc64/c++config.h: revision 1.8
lib/libc/stdlib/exit.c: revision 1.17
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.178
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3el/c++config.h: revision 1.21
distrib/sets/lists/debug/shl.mi: revision 1.179
distrib/sets/lists/debug/mi: revision 1.219
lib/libpthread/pthread.c: revision 1.150
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7/c++config.h: revision 1.14
libexec/ld.elf_so/symbols.map: revision 1.2
include/dlfcn.h: revision 1.25
external/gpl3/gcc/lib/libstdc++-v3/arch/arm/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/x86_64/c++config.h: revision 1.23
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64el/c++config.h: revision 1.18
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earm/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/mipsel/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/ia64/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhf/c++config.h: revision 1.17
distrib/sets/lists/tests/mi: revision 1.755
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/i386/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/vax/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/armeb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc/c++config.h: revision 1.20
lib/libc/dlfcn/dlfcn_elf.c: revision 1.14
tests/libexec/ld.elf_so/t_thread_local_dtor.sh: revision 1.1
tests/lib/libpthread/t_thread_local_dtor.sh: revision 1.1
lib/libc/stdlib/Makefile.inc: revision 1.93
lib/libc/include/atexit.h: revision 1.1
lib/libc/include/atexit.h: revision 1.2
external/gpl3/gcc/lib/libstdc++-v3/arch/m68k/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.180
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc64/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hfeb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/hppa/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hfeb/c++config.h: revision 1.14
lib/libc/stdlib/cxa_thread_atexit.c: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/h_helper_dso3.cpp: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/Makefile: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv64/c++config.h: revision 1.5
libexec/ld.elf_so/rtld.c: revision 1.185
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv32/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/m68000/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/mipseb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/coldfire/c++config.h: revision 1.12
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhfeb/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/alpha/c++config.h: revision 1.19
tests/libexec/ld.elf_so/Makefile: revision 1.9
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7eb/c++config.h: revision 1.14
tests/lib/libpthread/h_thread_local_dtor.cpp: revision 1.1
distrib/sets/lists/tests/shl.mi: revision 1.11
tests/lib/libpthread/Makefile: revision 1.13
libexec/ld.elf_so/rtld.h: revision 1.129
external/gpl3/gcc/lib/libstdc++-v3/arch/or1k/c++config.h: revision 1.6
Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.
If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.
Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
Fix filename of new debug file
Add misising DEBUGLIB file
Avoid common declaration.
Drop TLS variant checks, emutls is enough for VAX and Sun2.
 1.1.4.1 11-Jul-2017  bouyer file h_thread_local_dtor.cpp was added on branch netbsd-8 on 2017-08-29 11:25:50 +0000
 1.2 07-Nov-2010  jmmv Adjusts tests after import of atf-0.12:

- The use.fs property is gone.
- Mark the tests/fs/t_create:attrs test as broken when using the default
unprivileged-user:_atf setting. This probably deserves a fix somehow
but I'm not sure at this point.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file t_call_once.c was added on branch phil-wifi on 2019-06-10 22:10:07 +0000
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.4 05-Apr-2025  riastradh branches: 1.4.4;
Add tests for compat functions as cancellation points.

While here, test kevent too.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.3 31-Mar-2025  riastradh libpthread(3): Add missing cancellation points.

- accept4
- tcdrain

XXX Should our nonstandard alias paccept(2) also be a cancellation
point?

PR lib/59240: POSIX.1-2024: cancellation point audit
 1.2 31-Mar-2025  riastradh pthread_cancel(3): Rework.

Make pthread_setcancelstate(3) async-signal-safe. (As a side effect,
this also makes pthread_setcanceltype(3) async-signal-safe, although
that is not required.)

PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
 1.1 31-Mar-2025  riastradh pthread_cancel(3): Add some automatic tests.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
 1.4.4.2 02-Aug-2025  perseant Sync with HEAD
 1.4.4.1 05-Apr-2025  perseant file t_cancellation.c was added on branch perseant-exfatfs on 2025-08-02 05:58:09 +0000
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file t_cnd.c was added on branch phil-wifi on 2019-06-10 22:10:07 +0000
 1.3 25-Apr-2025  riastradh branches: 1.3.4;
t_compat_cancel: Use -1 rather than SIGALRM for expected signal.

On kernels without (e.g.) COMPAT_13, we get SIGSYS rather than
SIGALRM if the cancellation point doesn't cancel the syscall.

Won't help if we try to interrupt in-progress waits, but currently
none of the tests do that; we'll burn that bridge when we come to it,

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.2 11-Apr-2025  riastradh t_compat_cancel: Fix compat numbers to match reality.

- msync is as it existed in 1.2, and is implemented by compat12;
__msync13 was new in 1.3.

- sigsuspend is as it existed in 1.3, and is implemented by compat13;
__sigsuspend14 was new in 1.4.

(But, while select is as it existed in 5.0, and is implemented by
compat50, __select50 was new in _6.0_, not in 5.0.)

No functional change intended other than to rename the test cases for
clarity.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.1 05-Apr-2025  riastradh Add tests for compat functions as cancellation points.

While here, test kevent too.

PR lib/59240: POSIX.1-2024: cancellation point audit
PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.3.4.2 02-Aug-2025  perseant Sync with HEAD
 1.3.4.1 25-Apr-2025  perseant file t_compat_cancel.c was added on branch perseant-exfatfs on 2025-08-02 05:58:09 +0000
 1.8 10-Jun-2020  ad Adjust cond_timedwait_race to take account of spurious wakeups (which are
completely legit).
 1.7 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.6 03-Sep-2014  gson The cond_timedwait_race test case is no longer expected to fail; it
has been consistently passing since CVS date 2014.01.31.19.22.00.
See also PR lib/44756.
 1.5 19-Oct-2013  christos branches: 1.5.4;
fix unused variable warnings
 1.4 17-Mar-2013  jmmv Try to trigger the cond_timedwait_race race several times.

Sometime this tests passes (after all, it's exercising a race condition) and
when it does it's reported as a failure. By giving the test a few chances
to expose the problem, we prevent this noisy signal. When the race is really
addressed, this will start failing consistently as expected.
 1.3 27-Mar-2011  jruoho branches: 1.3.4; 1.3.10;
Add a test case for pthread_cond_timedwait(3) failures reported by
Sad Clouds in PR lib/44756. This was discussed also in:

http://mail-index.netbsd.org/tech-userlevel/2011/03/17/msg004689.html
 1.2 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.3.10.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.3.10.1 23-Jun-2013  tls resync from head
 1.3.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.5.4.1 22-Dec-2014  msaitoh Pull up following revision(s) (requested by gson in ticket #346):
tests/lib/libpthread/t_cond.c: revision 1.6
The cond_timedwait_race test case is no longer expected to fail; it
has been consistently passing since CVS date 2014.01.31.19.22.00.
See also PR lib/44756.
 1.10 11-Dec-2022  kre This test makes (made) a false assumption about the way that
process scheduling works. That a process (or in this case,
a thread) is no longer blocked at time T does not mean that it
will resume execution at time T. The OS is free to devote
resources to other processes/threads instead - all we should
normally be able to expect is that if it is not unblocked before
time T, that it will not start running before then.

In general though, the pthread_cond_*wait() functions don't guarantee
even that - but for this test, the possibility of something else
randomly signalling the condvar isn't believable, so don't worry about
that possibility (but do fail without calling strerror(0) on the off
chance it does happen).

Once we cease testing that the process resumed running before some
particular time, we can stop dealing with qemu timekeeping issues,
it might (seem to) take qemu twice as long as was requested before
the thread resumes, but that's OK - the same thing could happen on
a loaded system for other reasons.

Beyond that, the test also has (had) a race condition. When using
CLOCK_REALTIME though that clock needed to have advanced to T before
the ETIMEDOUT should happen, there is no guarantee that it will stay >T
(CLOCK_REALTIME is allowed to be reset backwards). So, only test
that the current time (after ETIMEDOUT) >= T when we're using
CLOCK_MONOTONIC - for CLOCK_REALTIME the time might have stepped
back between when the ETIMEDOUT happened and when the thread
obtains the current clock reading. For that case, all we can test
is that the ETIMEDOUT actually happens.

With much of what was there now gone, the code can be simplified,
we no longer need to do timespec arithmetic, just one comparison
(simpler to test that Tend >= Tstart+period than Tend-Tstart > period
as we need Tstart+period for the abstime value for the timeout anyway).

Note that this still tests for the issue reported in PR lib/47703
which is where the test came from in the first place.

ps: we seem to be missing pthread_cond_clockwait() which is the same
as pthread_cond_timedwait() except that the clock to use is passed
as a parameter, rather than as an attribute of the condition variable.
 1.9 16-Apr-2022  andvar fix various typos in comments and log messages.
 1.8 11-Aug-2019  martin Re-enable the QEMU specific timing limits, but only an increased upper
limit for now - let's see if that works on the test-bed.
 1.7 10-Aug-2019  martin PR lib/54440: adapt the FreeBSD change to this test and calculate time
differences more exact, allowing between 0 and 1 s delay between the
expected wakeup and the actual event happening.
Also convert the QEMU special case code to the same scheme, but for now
disable it (with XXX mark) and see if the proper timing limits fix that
case too.
If not, we will re-enable the QEMU special case.
 1.6 09-Jul-2019  maya return return atf_no_error() instead of 0 for consistency.

suggested by moritzbuhl in https://github.com/NetBSD/src/pull/11/
 1.5 16-Jan-2017  christos branches: 1.5.12;
PR/51884: Ngie Cooper: Include and message fixes
 1.4 12-Apr-2013  christos branches: 1.4.2; 1.4.8; 1.4.14; 1.4.18;
loosen the test only for qemu.
 1.3 12-Apr-2013  gson Make cond_wait_mono and cond_wait_real tests accept a wait time in the
range of 90% to 250% of nominal, to allow the test to pass under qemu
which has a known issue where timing can be off by a factor of two.
 1.2 29-Mar-2013  christos fix printf formats
 1.1 28-Mar-2013  christos Add pthread_cond_timedwait(3) test from PR/47703
 1.4.18.1 21-Apr-2017  bouyer Sync with HEAD
 1.4.14.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4.8.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.4.8.1 12-Apr-2013  yamt file t_condwait.c was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.4.2.2 23-Jun-2013  tls resync from head
 1.4.2.1 12-Apr-2013  tls file t_condwait.c was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.5.12.1 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2 16-Jan-2017  christos PR/51885: Ngie Cooper: Add delays to avoid races.
 1.1 24-Mar-2011  jruoho branches: 1.1.26; 1.1.30;
A dummy conformance-test for pthread_detach(3). I will extend this later.
 1.1.30.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.26.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 24-Mar-2011  jruoho A dummy conformance-test of pthread_equal(3).
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2 16-Jan-2017  christos PR/51886: Ngie Cooper: Use _exit instead of exit
 1.1 16-Jul-2010  jmmv branches: 1.1.28; 1.1.32;
Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1.32.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.28.1 20-Mar-2017  pgoyette Sync with HEAD
 1.3 16-Jan-2017  christos PR/51887: Ngie Cooper: Include and error message fixes
 1.2 27-Jan-2013  mbalmer branches: 1.2.12; 1.2.16;
exitting -> exiting.
 1.1 16-Jul-2010  jmmv branches: 1.1.6; 1.1.12;
Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1.12.1 25-Feb-2013  tls resync with head
 1.1.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.2.16.1 21-Apr-2017  bouyer Sync with HEAD
 1.2.12.1 20-Mar-2017  pgoyette Sync with HEAD
 1.10 29-Jan-2020  kamil Fix the t_join test

For pthread_attr_get_np() attr should be initialized prior to the call by
using pthread_attr_init(3). pthread_getattr_np() does this
automatically so switch to it.
 1.9 02-Jul-2017  joerg branches: 1.9.6;
Export the guard size of the main thread via vm.guard_size. Add a
complementary writable sysctl for the initial guard size of threads
created via pthread_create. Let the existing attribut accessors do the
right thing. Raise the default guard size for threads to 64KB.
 1.8 12-Mar-2012  joerg branches: 1.8.24;
Also exercise pthread_attr_setstacksize.
 1.7 12-Dec-2011  joerg Remove bogus check that (a) depends uninitialised memory (b) overflows a
buffer.
 1.6 22-Aug-2011  dholland branches: 1.6.2;
Requires stdint.h.
 1.5 30-Nov-2010  joerg Test alignment of constructor / destructor calls as well as the stack
of new threads. Currently implement for i386 and AMD64.
 1.4 29-Jul-2010  hans Revert to 1.1 and fix the casts by using uintptr_t. Ok jruoho.
 1.3 29-Jul-2010  jruoho One more cast.
 1.2 29-Jul-2010  jruoho Fix build failure on AMD64, noted by njoly@.
 1.1 28-Jul-2010  jruoho Add a simple test for pthread_join(3).
 1.6.2.1 17-Apr-2012  yamt sync with head
 1.8.24.1 31-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #234):
sys/arch/amd64/include/vmparam.h: revision 1.43
sys/kern/exec_subr.c: revision 1.79
lib/libpthread/pthread_int.h: revision 1.94
sys/arch/mips/include/vmparam.h: revision 1.58
sys/arch/mips/include/vmparam.h: revision 1.59
lib/libpthread/TODO: revision 1.19
sys/arch/powerpc/include/vmparam.h: revision 1.20
sys/arch/riscv/include/vmparam.h: revision 1.2
sys/arch/riscv/include/vmparam.h: revision 1.3
sys/arch/i386/include/vmparam.h: revision 1.85
tests/lib/libpthread/t_join.c: revision 1.9
sys/uvm/uvm_meter.c: revision 1.66
sys/uvm/uvm_param.h: revision 1.36
sys/kern/exec_subr.c: revision 1.80
sys/uvm/uvm_param.h: revision 1.37
sys/kern/exec_subr.c: revision 1.81
sys/kern/exec_subr.c: revision 1.82
lib/libpthread/pthread_attr_getguardsize.3: revision 1.4
lib/libpthread/pthread.c: revision 1.148
lib/libpthread/pthread_attr.c: revision 1.17
sys/arch/amd64/include/vmparam.h: revision 1.42
Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.
Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.
Revert for the moment, creates problems on i386.
Recommit exec_subr.c revision 1.79:
Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.
Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.
Additionally, change VM_DEFAULT_ADDRESS_TOPDOWN to include
user_stack_guard_size in the size reservation.
Update VM_DEFAULT_ADDRESS32_TOPDOWN to include guard area.
Export the guard size of the main thread via vm.guard_size. Add a
complementary writable sysctl for the initial guard size of threads
created via pthread_create. Let the existing attribut accessors do the
right thing. Raise the default guard size for threads to 64KB.
 1.9.6.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2 11-Jun-2020  martin Do not destroy mutices that failed to init - fixes a run with
PTHREAD_DIAGASSERT set to "a". Pointed out by joerg.
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file t_mtx.c was added on branch phil-wifi on 2019-06-10 22:10:07 +0000
 1.20 07-May-2022  rin Bump timeout for slow machines.
 1.19 01-Dec-2017  kre Since there has been no objection (or even comment) in response
to my message on tech-userlevel ...

Subject: tests/lib/libpthread/t_mutex:mutex6
Date: Thu, 23 Nov 2017 17:34:54 +0700
Message-ID: <28385.1511433294@andromeda.noi.kre.to>

which can be found at:
http://mail-index.netbsd.org/tech-userlevel/2017/11/23/msg011010.html

which analysed the mutex6 test case of this test, and concluded
that it was useless, nonsense, and broken (the whole test is just a
race - not even really using or testing mutexes), let it be henceforth
forever gone.
 1.18 01-Apr-2017  martin branches: 1.18.4;
Make the mutex6 test (which fails every know and then, but too rarely
to actually debug it) print some debug info when failing.
 1.17 23-Mar-2017  martin Avoid using an uninitialized mutex.
 1.16 05-Mar-2017  chs reenable mutex2 and mutex3 on powerpc now that PR 44387 is fixed.
 1.15 16-Jan-2017  christos PR/51888: Ngie Cooper: more error checking, missing includes
 1.14 31-Oct-2016  christos branches: 1.14.2;
more tests from kamil
 1.13 31-Oct-2016  christos fix typos
 1.12 31-Oct-2016  christos Merge and fix the timed mutex tests to use absolute time.
NB: the new tests are broken?
 1.11 30-Oct-2016  kamil Add new test t_timedmutex

This test is a clone on t_mutex with additional two tests for timed-mutex
specific block.

All simple-mutex (not with the timed property according to the C11 wording)
specific tests are covered by pthread_mutex_timedlock(3) with parameter
ts_lengthy of sufficiently large tv_sec value (right now UINT16_MAX). If,
a test will hang, it won't wait UINT16_MAX seconds, but will be terminated
within the default timeout for ATF tests (right now 300 [sec] in my
NetBSD/amd64 setup).

This test was inspired by a classic selflock test failure of
pthread_mutex_timedlock(3) of the following form:

#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
pthread_mutex_t mtx;
struct timespec ts;

ts.tv_sec = 0;
ts.tv_nsec = 1000;
printf("ts{.tv_sec = %d, .tv_nsec=%ld}\n", ts.tv_sec, ts.tv_nsec);
fflush(stdout);

printf("mtx_init\n");
assert(pthread_mutex_init(&mtx, NULL) == 0);

printf("mtx_lock\n");
assert(pthread_mutex_lock(&mtx) == 0);

printf("mtx_timedlock\n");
assert(pthread_mutex_timedlock(&mtx, &ts) == ETIMEDOUT);

printf("mtx_unlock\n");
assert(pthread_mutex_unlock(&mtx) == 0);

printf("mtx_destroy\n");
assert(pthread_mutex_destroy(&mtx) == 0);

return 0;
}

Current NetBSD implementation wrongly hangs on this test.

The issue was detected during development of the C11 portable threads.

My local tests in chroot presents that the are further issues:

t_timedmutex (21/25): 10 test cases
mutex1: [0.001142s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:75: *param != 20
mutex2: [0.261499s] Passed.
mutex3: [0.261496s] Passed.
mutex4: [0.001204s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:265: pthread_mutex_timedlock(&mutex, &ts_lengthy): Connection timed out
mutex5: [0.001235s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:337: pthread_mutex_timedlock(&mutex5, &ts_lengthy): Connection timed out
mutex6: [21.218497s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:512: start != 1
mutexattr1: [0.001328s] Passed.
mutexattr2: [0.001175s] Passed.
timedmutex1: [301.119397s] Failed: Test case timed out after 300 seconds
timedmutex2: [301.123081s] Failed: Test case timed out after 300 seconds
[623.990659s]

I'm also receiveing the same failure in the mutex6 test in t_mutex, so
there might be a false positives due to local chroot(8) issues.

Commit approved by <christos>.
 1.10 31-Jul-2016  christos we require root for sched_fifo, and more verbose messages.
 1.9 06-Jul-2016  christos branches: 1.9.2;
fix uninitialized var.
 1.8 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.7 04-Nov-2014  justin PR misc/49356 remove unnecessary references to atf-c/config.h

The function included via this header is not used and is removed in
later versions of atf, so let us avoid it.
 1.6 09-Feb-2014  jmmv Use compiler builtins instead of atf_arch and atf_machine.

The atf_arch and atf_machine configuration variables were removed from
atf-0.19 without me realizing that some tests were querying them directly.

Instead of reintroducing those variables, just rely on compiler builtins
as many other tests already do.

Should fix PR bin/48582.
 1.5 04-Apr-2011  martin branches: 1.5.4; 1.5.10;
Do only set a (lower than default) timeout value if we are on powerpc and
expect to run into a real deadrun ofter.
The (too short) timeout otherwise makes slower archs fail.
 1.4 21-Feb-2011  riz mutex2/mutex3 are expected to fail on powerpc because of
PR port-powerpc/44387.

XXX the ugly sleep at the end is because ATF will mark an un-triggered
race condition (ie, the test passes unexpectedly) as a test failure otherwise.
 1.3 20-Feb-2011  jmmv The mutex3 test is supposed to use a static initializer so that it differs
to the mutex2 test. This detail was lost during the atfification of these
tests.

Spotted by pooka@ and riz@.
 1.2 16-Jul-2010  njoly branches: 1.2.2;
Add missing pthread_mutex_init call in mutex3 testcase.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.5.10.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.4.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.9.2.5 26-Apr-2017  pgoyette Sync with HEAD
 1.9.2.4 20-Mar-2017  pgoyette Sync with HEAD
 1.9.2.3 04-Nov-2016  pgoyette Sync with HEAD
 1.9.2.2 06-Aug-2016  pgoyette Sync with HEAD
 1.9.2.1 01-Aug-2016  pgoyette Import test fix from HEAD.

With this, a complete test run on HEAD vs the localcount branch yields
identical lists of "Failed test cases" and "Expected failures"
 1.14.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.18.4.1 26-Feb-2018  snj Pull up following revision(s) (requested by maya in ticket #585):
tests/lib/libpthread/t_mutex.c: 1.19
Since there has been no objection (or even comment) in response
to my message on tech-userlevel ...
Subject: tests/lib/libpthread/t_mutex:mutex6
Date: Thu, 23 Nov 2017 17:34:54 +0700
Message-ID: <28385.1511433294%andromeda.noi.kre.to@localhost>
which can be found at:
http://mail-index.netbsd.org/tech-userlevel/2017/11/23/msg011010.html
which analysed the mutex6 test case of this test, and concluded
that it was useless, nonsense, and broken (the whole test is just a
race - not even really using or testing mutexes), let it be henceforth
forever gone.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.3 30-Mar-2025  riastradh tests/lib/libpthread/t_once: Test fork and pthread_once race.

Test is disabled by default because it triggers only with very low
probability in each trial, but let's make it easy to run if you want.

PR lib/59125: pthread_once(3) races with concurrent fork
 1.2 25-Aug-2017  ginsbach branches: 1.2.16;
PR/49003: Ngie Cooper: add <sys/time.h>
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2.16.1 02-Aug-2025  perseant Sync with HEAD
 1.2 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2 26-Jun-2015  pooka Check that PTHREAD_RWLOCK_INITIALIZER works.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.9 16-Jan-2017  christos PR/51889: Ngie Cooper: add sys/time.h
 1.8 04-Nov-2014  justin branches: 1.8.2; 1.8.4;
PR misc/49356 remove unnecessary references to atf-c/config.h

The function included via this header is not used and is removed in
later versions of atf, so let us avoid it.
 1.7 09-Mar-2012  joerg It is perfectly valid for sem_wait to be interrupted, so loop on EINTR.
 1.6 07-Mar-2012  joerg Remove libpthread's semaphore implementation and always use the kernel
one. The implementation doesn't provide an async-safe sem_post and can't
without a lot of work on the pthread primitives.

Remove bogus time out requirement in test case, it should have been
a "known failure" if anything.
 1.5 03-Nov-2010  christos branches: 1.5.6;
add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.4 21-Jul-2010  jmmv before_start_one_thread is not racy only in amd64; my confusion. Mark it
as an xfail everywhere and, while doing so, make the test longer so that
we trigger the failure all the time -- of course, being a race this may
still happen but the chances should be pretty low.
 1.3 19-Jul-2010  jmmv Split the before_start test in two: one that does not use threads and one
that does. The former works all the time but the latter gets consistently
stuck on amd64. Mark the latter as an expected timeout (should be a "race
condition" test, but atf does not have such a thing yet[1]).

This clears the test failures, at least, under anita running NetBSD/i386.

From pooka@: this could well be because calling sem_post(3) from a signal
handler can't possibly do the right thing with the pthread implementation.
However, according to signal(7), sem_post(3) is signal-async safe...

While here, program alarms using a timeout shorter than 1 second to speed
up the execution of the tests.

1: Good thing is I finally understand what a "race condition" test looks
like, I believe.
 1.2 18-Jul-2010  pooka Reduce sleep time for practically the same effect. Until atf can
do parallel test execution, tests which spend 99.9999% of their
execution sleeping are not nice.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.5.6.1 17-Apr-2012  yamt sync with head
 1.8.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.8.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.3 19-Oct-2013  christos fix unused variable warnings
 1.2 03-Nov-2010  christos branches: 1.2.6; 1.2.12;
add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.2.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.6.1 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.6 28-Nov-2023  riastradh branches: 1.6.2; 1.6.4; 1.6.6;
pthread: Don't adjust user-allocated stack addresses by guardsize.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.5 28-Nov-2023  riastradh libpthread/t_stack: Fix format string for size_t.

Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.4 27-Nov-2023  riastradh libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.

The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.

Noted by prlw1.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.3 27-Nov-2023  riastradh libpthread/t_stack: Omit needless cast in previous.

Arose from an earlier draft of the change.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.2 27-Nov-2023  riastradh libpthread/t_stack: Make this more robust to the guard size bug.

Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.1 24-Nov-2023  riastradh pthread: Add tests for pthread user stack allocation.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.6.6.2 09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1924):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.6.6.1 28-Nov-2023  martin file t_stack.c was added on branch netbsd-8 on 2023-12-09 13:36:02 +0000
 1.6.4.2 09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1775):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.6.4.1 28-Nov-2023  martin file t_stack.c was added on branch netbsd-9 on 2023-12-09 13:24:23 +0000
 1.6.2.2 28-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #478):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.6.2.1 28-Nov-2023  martin file t_stack.c was added on branch netbsd-10 on 2023-11-28 13:17:11 +0000
 1.3 06-Apr-2011  jruoho As per PR lib/44818, remove 'lib/libpthread/t_status'. It takes two minutes
to rewrite this properly if someone misses this.
 1.2 03-Nov-2010  christos add Makefile.inc everywhere so that we can set WARNS=4 by default. Amazing
how many bugs this found :-)
 1.1 16-Jul-2010  jmmv Convert the libpthread tests to atf.
Initial work from the GSoC 2008 project by Lukasz Strzygowski.

I think that this, together with the previous conversion of librt, obsoletes
the tests in the semaphore/ directory. Will investigate later.
 1.9 28-Feb-2018  uwe Simplify - it's enough to set nctx.uc_link to &octx to restore old
context automatically when swapfunc() returns.
 1.8 28-Feb-2018  uwe Add missing $ in the RCSID.
 1.7 27-Feb-2018  uwe threadfunc - we do return from swapcontext() (since revision 1.2),
so drop the NOTREACHED comment.
 1.6 27-Feb-2018  uwe swapfunc() is not passed to pthread_create, there's no need for it to
have any arguments.
 1.5 27-Feb-2018  uwe Drop unnecessary cast to makecontext() argument.
 1.4 27-Feb-2018  uwe Cleanup trailing whitespace.
 1.3 16-Jan-2017  christos PR/51890: Ngie Cooper: include and error message fixes.
 1.2 25-Aug-2014  bouyer branches: 1.2.2; 1.2.4;
Go back to the initial context (as tests/lib/libc/sys/t_swapcontext.c does)
after checking pthread_self() didn't change. Otherwise the process exits
outside of atf context.
Should fix "Test case exited normally but failed to create the results file: Results file is empty" reports from atf-run.
 1.1 12-Sep-2012  manu branches: 1.1.4; 1.1.12;
setcontext() used to be incompatible with -lpthread since it affected
the TLS pointer, therefore wrecking the pthread environement.

Some ports had _UC_TLSBASE flag or equivalent (_UC_UNIQUE on alpha)
that controlled whether setcontext() would change the TLS pointer.
This change let libpthread override setcontext() with its own version
that unsets _UC_TLSBASE, enabling safe usage of setcontext() with
-lpthread.

We also have the following required changes here:
- rename alpha's _UC_UNIQUE into _UC_TLSBASE
- add _UC_TLSBASE definition in header file for all ports
(powerpc, sh3, sparc and sparc64 lack the implementation for now)
- introduce a libc stub that can be overriden for setcontext()
- modify MD libcs swapcontext() implementations so that they use the
setcontext() libc stub instead of doing a plain system call.

While we are there:
- document various MD _UC_* flags in header file
- add libc and libpthread tests for swapcontext() behavior
(hopefully helpful to spot MD problems introduced with this change)

Future work:
- Deciding whether kernel support or _UC_TLSBASE should be added for
powerpc, sh3, sparc and sparc64 is left to portmasters
sparc64

Approved by core@
 1.1.12.1 29-Aug-2014  martin Pull up following revision(s) (requested by bouyer in ticket #63):
tests/lib/libpthread/t_swapcontext.c: revision 1.2
Go back to the initial context (as tests/lib/libc/sys/t_swapcontext.c does)
after checking pthread_self() didn't change. Otherwise the process exits
outside of atf context.
Should fix "Test case exited normally but failed to create the results file: Results file is empty" reports from atf-run.
 1.1.4.2 30-Oct-2012  yamt sync with head
 1.1.4.1 12-Sep-2012  yamt file t_swapcontext.c was added on branch yamt-pagecache on 2012-10-30 19:00:04 +0000
 1.2.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.2.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2 14-May-2020  msaitoh Remove extra semicolon.
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file t_thrd.c was added on branch phil-wifi on 2019-06-10 22:10:07 +0000
 1.1 11-Jul-2017  joerg branches: 1.1.4;
Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.

If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.

Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
 1.1.4.2 29-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #127):
tests/libexec/ld.elf_so/h_thread_local_dtor.c: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmeb/c++config.h: revision 1.17
lib/libc/stdlib/atexit.h: file removal
lib/libc/stdlib/exit.c: revision 1.16
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc64/c++config.h: revision 1.8
lib/libc/stdlib/exit.c: revision 1.17
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.178
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3el/c++config.h: revision 1.21
distrib/sets/lists/debug/shl.mi: revision 1.179
distrib/sets/lists/debug/mi: revision 1.219
lib/libpthread/pthread.c: revision 1.150
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7/c++config.h: revision 1.14
libexec/ld.elf_so/symbols.map: revision 1.2
include/dlfcn.h: revision 1.25
external/gpl3/gcc/lib/libstdc++-v3/arch/arm/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/x86_64/c++config.h: revision 1.23
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64el/c++config.h: revision 1.18
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earm/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/mipsel/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/ia64/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhf/c++config.h: revision 1.17
distrib/sets/lists/tests/mi: revision 1.755
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/i386/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/vax/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/armeb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc/c++config.h: revision 1.20
lib/libc/dlfcn/dlfcn_elf.c: revision 1.14
tests/libexec/ld.elf_so/t_thread_local_dtor.sh: revision 1.1
tests/lib/libpthread/t_thread_local_dtor.sh: revision 1.1
lib/libc/stdlib/Makefile.inc: revision 1.93
lib/libc/include/atexit.h: revision 1.1
lib/libc/include/atexit.h: revision 1.2
external/gpl3/gcc/lib/libstdc++-v3/arch/m68k/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.180
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc64/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hfeb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/hppa/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hfeb/c++config.h: revision 1.14
lib/libc/stdlib/cxa_thread_atexit.c: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/h_helper_dso3.cpp: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/Makefile: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv64/c++config.h: revision 1.5
libexec/ld.elf_so/rtld.c: revision 1.185
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv32/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/m68000/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/mipseb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/coldfire/c++config.h: revision 1.12
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhfeb/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/alpha/c++config.h: revision 1.19
tests/libexec/ld.elf_so/Makefile: revision 1.9
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7eb/c++config.h: revision 1.14
tests/lib/libpthread/h_thread_local_dtor.cpp: revision 1.1
distrib/sets/lists/tests/shl.mi: revision 1.11
tests/lib/libpthread/Makefile: revision 1.13
libexec/ld.elf_so/rtld.h: revision 1.129
external/gpl3/gcc/lib/libstdc++-v3/arch/or1k/c++config.h: revision 1.6
Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.
If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.
Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
Fix filename of new debug file
Add misising DEBUGLIB file
Avoid common declaration.
Drop TLS variant checks, emutls is enough for VAX and Sun2.
 1.1.4.1 11-Jul-2017  bouyer file t_thread_local_dtor.sh was added on branch netbsd-8 on 2017-08-29 11:25:50 +0000
 1.2 31-Oct-2016  christos branches: 1.2.2;
Merge and fix the timed mutex tests to use absolute time.
NB: the new tests are broken?
 1.1 30-Oct-2016  kamil Add new test t_timedmutex

This test is a clone on t_mutex with additional two tests for timed-mutex
specific block.

All simple-mutex (not with the timed property according to the C11 wording)
specific tests are covered by pthread_mutex_timedlock(3) with parameter
ts_lengthy of sufficiently large tv_sec value (right now UINT16_MAX). If,
a test will hang, it won't wait UINT16_MAX seconds, but will be terminated
within the default timeout for ATF tests (right now 300 [sec] in my
NetBSD/amd64 setup).

This test was inspired by a classic selflock test failure of
pthread_mutex_timedlock(3) of the following form:

#include <assert.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
pthread_mutex_t mtx;
struct timespec ts;

ts.tv_sec = 0;
ts.tv_nsec = 1000;
printf("ts{.tv_sec = %d, .tv_nsec=%ld}\n", ts.tv_sec, ts.tv_nsec);
fflush(stdout);

printf("mtx_init\n");
assert(pthread_mutex_init(&mtx, NULL) == 0);

printf("mtx_lock\n");
assert(pthread_mutex_lock(&mtx) == 0);

printf("mtx_timedlock\n");
assert(pthread_mutex_timedlock(&mtx, &ts) == ETIMEDOUT);

printf("mtx_unlock\n");
assert(pthread_mutex_unlock(&mtx) == 0);

printf("mtx_destroy\n");
assert(pthread_mutex_destroy(&mtx) == 0);

return 0;
}

Current NetBSD implementation wrongly hangs on this test.

The issue was detected during development of the C11 portable threads.

My local tests in chroot presents that the are further issues:

t_timedmutex (21/25): 10 test cases
mutex1: [0.001142s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:75: *param != 20
mutex2: [0.261499s] Passed.
mutex3: [0.261496s] Passed.
mutex4: [0.001204s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:265: pthread_mutex_timedlock(&mutex, &ts_lengthy): Connection timed out
mutex5: [0.001235s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:337: pthread_mutex_timedlock(&mutex5, &ts_lengthy): Connection timed out
mutex6: [21.218497s] Failed: /usr/src/tests/lib/libpthread/t_timedmutex.c:512: start != 1
mutexattr1: [0.001328s] Passed.
mutexattr2: [0.001175s] Passed.
timedmutex1: [301.119397s] Failed: Test case timed out after 300 seconds
timedmutex2: [301.123081s] Failed: Test case timed out after 300 seconds
[623.990659s]

I'm also receiveing the same failure in the mutex6 test in t_mutex, so
there might be a false positives due to local chroot(8) issues.

Commit approved by <christos>.
 1.2.2.2 04-Nov-2016  pgoyette Sync with HEAD
 1.2.2.1 31-Oct-2016  pgoyette file t_timedmutex.c was added on branch pgoyette-localcount on 2016-11-04 14:49:23 +0000
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file t_tss.c was added on branch phil-wifi on 2019-06-10 22:10:07 +0000
 1.1 21-Mar-2013  christos branches: 1.1.4; 1.1.10;
new dlopen tests for libpthread from manu@
 1.1.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.10.1 21-Mar-2013  yamt file Makefile was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 21-Mar-2013  tls file Makefile was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.1 21-Mar-2013  christos branches: 1.1.4; 1.1.10;
new dlopen tests for libpthread from manu@
 1.1.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.10.1 21-Mar-2013  yamt file t_dlopen.c was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 21-Mar-2013  tls file t_dlopen.c was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.1 21-Mar-2013  christos branches: 1.1.4; 1.1.10;
new dlopen tests for libpthread from manu@
 1.1.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.10.1 21-Mar-2013  yamt file t_dso_pthread_create.c was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 21-Mar-2013  tls file t_dso_pthread_create.c was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.1 21-Mar-2013  christos branches: 1.1.4; 1.1.10;
new dlopen tests for libpthread from manu@
 1.1.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.10.1 21-Mar-2013  yamt file t_main_pthread_create.c was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 21-Mar-2013  tls file t_main_pthread_create.c was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.1 21-Mar-2013  christos branches: 1.1.4; 1.1.10;
new dlopen tests for libpthread from manu@
 1.1.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.10.1 21-Mar-2013  yamt file Makefile was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 21-Mar-2013  tls file Makefile was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.1 21-Mar-2013  christos branches: 1.1.4; 1.1.10;
new dlopen tests for libpthread from manu@
 1.1.10.2 22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.1.10.1 21-Mar-2013  yamt file h_pthread_dlopen.c was added on branch yamt-pagecache on 2014-05-22 11:42:22 +0000
 1.1.4.2 23-Jun-2013  tls resync from head
 1.1.4.1 21-Mar-2013  tls file h_pthread_dlopen.c was added on branch tls-maxphys on 2013-06-23 06:28:57 +0000
 1.2 18-Oct-2025  riastradh tests/lib/libpthread: Fix tests in subdirectory.

Need to use TESTS_SUBDIRS for this, not SUBDIR. Avoid the extra
nesting level while here; can make the library be a subdirectory of
the directory where the tests live.

PR lib/59685: libcrypto should not depend on libpthread
 1.1 06-Oct-2025  riastradh libpthread: Test pthread stubs in threaded vs non-threaded programs.

PR lib/59685: libcrypto should not depend on libpthread
 1.1 06-Oct-2025  riastradh libpthread: Test pthread stubs in threaded vs non-threaded programs.

PR lib/59685: libcrypto should not depend on libpthread
 1.1 18-Oct-2025  riastradh tests/lib/libpthread: Fix tests in subdirectory.

Need to use TESTS_SUBDIRS for this, not SUBDIR. Avoid the extra
nesting level while here; can make the library be a subdirectory of
the directory where the tests live.

PR lib/59685: libcrypto should not depend on libpthread
 1.1 18-Oct-2025  riastradh tests/lib/libpthread: Fix tests in subdirectory.

Need to use TESTS_SUBDIRS for this, not SUBDIR. Avoid the extra
nesting level while here; can make the library be a subdirectory of
the directory where the tests live.

PR lib/59685: libcrypto should not depend on libpthread
 1.1 06-Oct-2025  riastradh libpthread: Test pthread stubs in threaded vs non-threaded programs.

PR lib/59685: libcrypto should not depend on libpthread
 1.1 06-Oct-2025  riastradh libpthread: Test pthread stubs in threaded vs non-threaded programs.

PR lib/59685: libcrypto should not depend on libpthread
 1.1 06-Oct-2025  riastradh libpthread: Test pthread stubs in threaded vs non-threaded programs.

PR lib/59685: libcrypto should not depend on libpthread

RSS XML Feed