cosmopolitan/libc/thread
Justine Tunney 98c5847727
Fix fork waiter leak in nsync
This change fixes a bug where nsync waiter objects would leak. It'd mean
that long-running programs like runitd would run out of file descriptors
on NetBSD where waiter objects have ksem file descriptors. On other OSes
this bug is mostly harmless since the worst that can happen with a futex
is to leak a little bit of ram. The bug was caused because tib_nsync was
sneaking back in after the finalization code had cleared it. This change
refactors the thread exiting code to handle nsync teardown appropriately
and in making this change I found another issue, which is that user code
which is buggy, and tries to exit without joining joinable threads which
haven't been detached, would result in a deadlock. That doesn't sound so
bad, except the main thread is a joinable thread. So this deadlock would
be triggered in ways that put libc at fault. So we now auto-join threads
and libc will log a warning to --strace when that happens for any thread
2024-12-31 01:30:13 -08:00
..
alarm.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
BUILD.mk Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
freebsd.internal.h Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
getitimer.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
getstackbottom.c Rewrite memory manager 2024-06-22 05:45:11 -07:00
itimer.c Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
itimer.h Make threads faster and more reliable 2024-12-21 22:13:00 -08:00
lock.h Eliminate cyclic locks in runtime 2024-12-16 22:25:12 -08:00
makecontext.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
mapstack.c Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
mktls.c Fix fork waiter leak in nsync 2024-12-31 01:30:13 -08:00
openbsd.internal.h Rewrite memory manager 2024-06-22 05:45:11 -07:00
posixthread.internal.h Fix fork waiter leak in nsync 2024-12-31 01:30:13 -08:00
pt.internal.h Improve multithreading 2024-07-21 14:40:45 -07:00
pthread_atfork.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_attr_destroy.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_getdetachstate.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_getguardsize.c Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
pthread_attr_getinheritsched.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_getschedparam.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_getschedpolicy.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_getscope.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_getsigaltstack_np.c Improve multithreading 2024-07-21 14:40:45 -07:00
pthread_attr_getsigaltstacksize_np.c Improve multithreading 2024-07-21 14:40:45 -07:00
pthread_attr_getsigmask_np.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
pthread_attr_getstack.c Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
pthread_attr_getstacksize.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_init.c Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
pthread_attr_setdetachstate.c Make threads faster and more reliable 2024-12-21 22:13:00 -08:00
pthread_attr_setguardsize.c Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
pthread_attr_setinheritsched.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_setschedparam.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_setschedpolicy.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_setscope.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_attr_setsigaltstack_np.c Improve multithreading 2024-07-21 14:40:45 -07:00
pthread_attr_setsigaltstacksize_np.c Improve multithreading 2024-07-21 14:40:45 -07:00
pthread_attr_setsigmask_np.c Make threads faster and more reliable 2024-12-21 22:13:00 -08:00
pthread_attr_setstack.c Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
pthread_attr_setstacksize.c Improve memory manager and signal handling 2024-12-27 01:33:00 -08:00
pthread_barrier_destroy.c Make more improvements to threads and mappings 2024-07-24 01:19:54 -07:00
pthread_barrier_init.c Make more improvements to threads and mappings 2024-07-24 01:19:54 -07:00
pthread_barrier_wait.c Introduce cosmo_futex_wait and cosmo_futex_wake 2024-11-22 11:25:15 -08:00
pthread_barrierattr_destroy.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_barrierattr_getpshared.c Make more improvements to threads and mappings 2024-07-24 01:19:54 -07:00
pthread_barrierattr_init.c Make more improvements to threads and mappings 2024-07-24 01:19:54 -07:00
pthread_barrierattr_setpshared.c Make more improvements to threads and mappings 2024-07-24 01:19:54 -07:00
pthread_cancel.c Fix bugs in poll(), select(), ppoll(), and pselect() 2024-09-02 00:29:52 -07:00
pthread_cond_broadcast.c Eliminate cyclic locks in runtime 2024-12-16 22:25:12 -08:00
pthread_cond_destroy.c Eliminate cyclic locks in runtime 2024-12-16 22:25:12 -08:00
pthread_cond_init.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_cond_signal.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_cond_timedwait.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_cond_wait.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_condattr_destroy.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_condattr_getclock.c Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
pthread_condattr_getpshared.c Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
pthread_condattr_init.c Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
pthread_condattr_setclock.c Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
pthread_condattr_setpshared.c Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
pthread_create.c Fix fork waiter leak in nsync 2024-12-31 01:30:13 -08:00
pthread_decimate_np.c Fix fork waiter leak in nsync 2024-12-31 01:30:13 -08:00
pthread_detach.c Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
pthread_equal.c Add much of C11 threads.h API 2024-04-28 07:04:08 -07:00
pthread_exit.c Fix fork waiter leak in nsync 2024-12-31 01:30:13 -08:00
pthread_getaffinity_np.c Make some improvements of little consequence 2024-07-27 08:20:18 -07:00
pthread_getattr_np.c Improve memory manager and signal handling 2024-12-27 01:33:00 -08:00
pthread_getname_np.c Remove .internal from more header filenames 2024-08-04 12:52:25 -07:00
pthread_getschedparam.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_getspecific.c Make malloc() go 200x faster 2024-06-05 02:02:14 -07:00
pthread_getthreadid_np.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_getunique_np.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_join.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_key_create.c Make POSIX threads improvements 2024-06-30 15:38:59 -07:00
pthread_key_delete.c Make POSIX threads improvements 2024-06-30 15:38:59 -07:00
pthread_kill.c Make threads faster and more reliable 2024-12-21 22:13:00 -08:00
pthread_mutex_consistent.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutex_destroy.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutex_init.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutexattr_destroy.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutexattr_getpshared.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutexattr_gettype.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutexattr_init.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutexattr_setpshared.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_mutexattr_settype.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_once.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_reschedule.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_rwlock_destroy.c Support process shared pthread_rwlock 2024-12-13 03:00:06 -08:00
pthread_rwlock_init.c Support process shared pthread_rwlock 2024-12-13 03:00:06 -08:00
pthread_rwlock_rdlock.c Avoid pthread_rwlock_wrlock() starvation 2024-12-24 10:30:11 -08:00
pthread_rwlock_tryrdlock.c Support process shared pthread_rwlock 2024-12-13 03:00:06 -08:00
pthread_rwlock_trywrlock.c Support process shared pthread_rwlock 2024-12-13 03:00:06 -08:00
pthread_rwlock_unlock.c Support process shared pthread_rwlock 2024-12-13 03:00:06 -08:00
pthread_rwlock_wrlock.c Avoid pthread_rwlock_wrlock() starvation 2024-12-24 10:30:11 -08:00
pthread_rwlockattr_destroy.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_rwlockattr_getpshared.c Support process shared pthread_rwlock 2024-12-13 03:00:06 -08:00
pthread_rwlockattr_init.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_rwlockattr_setpshared.c Support process shared pthread_rwlock 2024-12-13 03:00:06 -08:00
pthread_self.c Add much of C11 threads.h API 2024-04-28 07:04:08 -07:00
pthread_setaffinity_np.c Make some improvements of little consequence 2024-07-27 08:20:18 -07:00
pthread_setcanceltype.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
pthread_setname_np.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
pthread_setschedparam.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_setschedparam_freebsd.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_setschedprio.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_sigmask.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
pthread_spin_destroy.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_spin_init.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_spin_lock.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_spin_trylock.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_spin_unlock.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
pthread_timedjoin_np.c Fix fork waiter leak in nsync 2024-12-31 01:30:13 -08:00
pthread_tryjoin_np.c Work around copy_file_range() bug in eCryptFs 2024-09-29 16:35:38 -07:00
pthread_zombify.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
README.md Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
sem_destroy.c Speed up unnamed POSIX semaphores 2024-09-13 06:25:27 -07:00
sem_getvalue.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
sem_init.c Speed up unnamed POSIX semaphores 2024-09-13 06:25:27 -07:00
sem_open.c Allow user to override pthread mutex and cond 2024-12-23 21:57:52 -08:00
sem_post.c Introduce cosmo_futex_wait and cosmo_futex_wake 2024-11-22 11:25:15 -08:00
sem_timedwait.c Introduce cosmo_futex_wait and cosmo_futex_wake 2024-11-22 11:25:15 -08:00
sem_trywait.c Apply clang-format update to repo (#1154) 2024-04-25 10:38:00 -07:00
sem_wait.c flip et / noet in modelines 2023-12-07 22:17:11 -05:00
semaphore.h Remove bad defines from early days of project 2024-07-24 12:11:21 -07:00
setitimer.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00
thrd_create.c Add much of C11 threads.h API 2024-04-28 07:04:08 -07:00
thrd_detach.c Add much of C11 threads.h API 2024-04-28 07:04:08 -07:00
thrd_join.c Add much of C11 threads.h API 2024-04-28 07:04:08 -07:00
thread.h Reduce stack virtual memory consumption on Linux 2024-12-25 20:58:08 -08:00
thread2.h Add dontthrow attribute to most libc functions 2024-01-09 01:26:03 -08:00
threads.h Remove more _Atomic keywords from public headers 2024-07-24 13:56:03 -07:00
tls.h Fix fork waiter leak in nsync 2024-12-31 01:30:13 -08:00
ualarm.c Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
xnu.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00

Cosmpolitan POSIX Threads Library

Cosmopolitan Libc implements threading as it is written in The Open Group Base Specifications Issue 7, 2018 edition IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008) in addition to GNU extensions.