Home | History | Annotate | Download | only in libpthread
History log of /src/lib/libpthread/pthread_tsd.c
RevisionDateAuthorComments
 1.26  01-Mar-2025  christos Explain that the pthread_atfork() call will not call malloc from here.
 1.25  10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.24  12-Feb-2022  riastradh libpthread: Move namespacing include to top of .c files.

Stuff like libc's namespace.h, or atomic_op_namespace.h, which does
namespacing tricks like `#define atomic_cas_uint _atomic_cas_uint',
has to go at the top of each .c file. If it goes in the middle, it
might be too late to affect the declarations, and result in compile
errors.

I tripped over this by including <sys/atomic.h> in mips
<machine/lock.h>.

(Maybe we should create a new pthread_namespace.h file for the
purpose, but this'll do for now.)
 1.23  11-Jun-2020  ad Drop self->pt_lock before clearing TSD / malloc TSD.
 1.22  19-Apr-2020  joerg Improve TSD behavior

Optimistically check whether the key has been used by this thread
already and avoid locking in that case. This avoids the atomic operation
in the hot path. When the value is set to non-NULL for the first time,
put the entry on the to-be-freed list and keep it their until
destruction or thread exit. Setting the key to NULL and back is common
enough and updating the list is more expensive than the extra check on
the final round.
 1.21  19-Apr-2020  joerg Reinit TSD mutex in the child to avoid issues with former waiters
 1.20  16-Feb-2020  kamil Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.
 1.19  15-Feb-2020  kamil Enhance the pthread(3) + malloc(3) init model

Separate the pthread_atfork(3) call from pthread_tsd_init()
and move it into a distinct function.

Call inside pthread__init() late TSD initialization route, just after
"pthread_atfork(NULL, NULL, pthread__fork_callback);".

Document that malloc(3) initialization is now controlled again and called
during the first pthread_atfork(3) call.

Remove #if 0 code from pthread_mutex.c as we no longer initialize malloc
prematurely.
 1.18  25-Dec-2019  joerg Since pthread_setspecific requires locks, ensure that they are acquired
before fork and dropped in both parent and child. At least Python
depends on TSD after fork, even though it is undefined behavior in
POSIX.
 1.17  05-Mar-2019  christos Transfer all the keys that were created in the libc stub implementation
to the pthread tsd implementation when the main thread is created.
This corrects a problem where a process created keys before libpthread
was loaded (either from the libc constructor or because libpthread
was dlopened later). This fixes a problem with jemalloc which creates
keys in the constructor.
 1.16  09-Jul-2017  christos branches: 1.16.6;
PR/52386: Use the number of iterations we document.
 1.15  25-Aug-2015  pooka branches: 1.15.8;
Revert 1.14 now that the arduous task of fixing rumphijack to allow
mmap() in early init has been completed.
 1.14  30-May-2015  christos Thanks rump for not letting us use even mmap during initialization.
 1.13  29-May-2015  christos Fix previous: Can't use calloc/malloc before we complete initialization
of the thread library, because malloc uses pthread_foo_specific, and it will
end up initializing itself incorrectly.
 1.12  29-May-2015  manu Make PTHREAD_KEYS_MAX dynamically adjustable

NetBSD's PTHREAD_KEYS_MAX is set to 256, which is low compared to
other systems like Linux (1024) or MacOS X (512). As a result some
setups tested on Linux will exhibit problems on NetBSD because of
pthread_keys usage beyond the limit. This happens for instance on
Apache with various module loaded, and in this case no particular
developper can be blamed for going beyond the limit, since several
modules from different sources contribute to the problem.

This patch makes the limit conigurable through the PTHREAD_KEYS_MAX
environement variable. If undefined, the default remains unchanged
(256). In any case, the value cannot be lowered below POSIX-mandated
_POSIX_THREAD_KEYS_MAX (128).

While there:
- use EXIT_FAILURE instead of 1 when calling err(3) in libpthread.
- Reset _POSIX_THREAD_KEYS_MAX to POSIX mandated 128, instead of 256.
 1.11  21-Mar-2013  christos branches: 1.11.8;
- Allow libpthread to be dlopened again, by providing libc stubs to libpthread.
- Fail if the dlopened libpthread does pthread_create(). From manu@
- Discussed at length in the mailing lists; approved by core@
- This was chosen as the least intrusive patch that will provide
the necessary functionality.
XXX: pullup to 6
 1.10  22-Nov-2012  christos Don't call the destructor in pthread_key_delete() following the standard.
 1.9  21-Nov-2012  christos Replace the simple implementation of pthread_key_{create,destroy}
and pthread_{g,s}etspecific functions, to one that invalidates
values of keys in other threads when pthread_key_delete() is called.
This fixes chromium, which expects pthread_key_delete() to do
cleanup in all threads.
 1.8  02-Mar-2012  joerg branches: 1.8.2;
Fix indentation.
 1.7  28-Apr-2008  martin branches: 1.7.4; 1.7.8; 1.7.24;
Remove clause 3 and 4 from TNF licenses
 1.6  08-Mar-2008  ad branches: 1.6.2;
Add a cast to make lint happy.
 1.5  07-Mar-2008  ad pthread_key_create: instead of using a simple 1/0 value to record a key
as allocated, use an array of pointers and save __builtin_return_address(0)
so keys can be identified when doing post-mortem debugging.
 1.4  24-Dec-2007  ad branches: 1.4.2;
- Fix pthread_rwlock_trywrlock() which was broken.

- Add new functions: pthread_mutex_held_np, mutex_owner_np, rwlock_held_np,
rwlock_wrheld_np, rwlock_rdheld_np. These match the kernel's locking
primitives and can be used when porting kernel code to userspace.

- Always create LWPs detached. Do join/exit sync mostly in userland. When
looped on a dual core box this seems ~30% quicker than using lwp_wait().
Reduce number of lock acquire/release ops during thread exit.
 1.3  16-Aug-2007  ad branches: 1.3.2;
- Reinitialize the absolute minimum when recycling user thread state.
Chops another ~10% off create/join in a loop on i386.
- Disable low level debugging as this is stable. Improves benchmarks
across the board by a small percentage. Uncontested mutex acquire
and release in a loop becomes about 8% quicker.
- Minor cleanup.
 1.2  29-Sep-2003  wiz branches: 1.2.20;
available, not avaliable. From miod@openbsd.
 1.1  13-Aug-2003  nathanw Split out pthread_{set,get}specific() into a separate file and arrange
for that file to not be built with profiling. This makes it reasonable to
use pthread_{set,get}specific() to implement thread-safe profiline call counts.
 1.2.20.1  03-Sep-2007  skrll Sync with HEAD.
 1.3.2.2  23-Mar-2008  matt sync with HEAD
 1.3.2.1  09-Jan-2008  matt sync with HEAD
 1.4.2.1  24-Mar-2008  keiichi sync with head.
 1.6.2.1  18-May-2008  yamt sync with head.
 1.7.24.3  29-Apr-2013  riz Pull up following revision(s) (requested by manu in ticket #869):
lib/libpthread/pthread_rwlock.c: revision 1.33
lib/libc/include/reentrant.h: revision 1.16
lib/libpthread/pthread_cond.c: revision 1.59
lib/libpthread/pthread_misc.c: revision 1.15
lib/libc/thread-stub/thread-stub.c: revision 1.23
lib/libpthread/pthread_cancelstub.c: revision 1.38
lib/libpthread/pthread_specific.c: revision 1.26
lib/libpthread/pthread_mutex.c: revision 1.56
lib/libpthread/pthread_tsd.c: revision 1.11
lib/libpthread/Makefile: revision 1.80
lib/libpthread/pthread.c: revision 1.143
lib/libpthread/pthread_int.h: revision 1.89
- Allow libpthread to be dlopened again, by providing libc stubs to
libpthread.
- Fail if the dlopened libpthread does pthread_create(). From manu@
- Discussed at length in the mailing lists; approved by core@
- This was chosen as the least intrusive patch that will provide
the necessary functionality.
XXX: pullup to 6
 1.7.24.2  02-Dec-2012  riz Back out ticket #724 (libpthread changes) until they can be better
understood, as they broke threaded programs on (at least) i386 and amd64.
 1.7.24.1  28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #724):
lib/libpthread/pthread_specific.c: revision 1.24
lib/libpthread/pthread_tsd.c: revision 1.10
lib/libpthread/pthread_tsd.c: revision 1.9
lib/libpthread/pthread_int.h: revision 1.88
Replace the simple implementation of pthread_key_{create,destroy}
and pthread_{g,s}etspecific functions, to one that invalidates
values of keys in other threads when pthread_key_delete() is called.
This fixes chromium, which expects pthread_key_delete() to do
cleanup in all threads.
Don't call the destructor in pthread_key_delete() following the standard.
 1.7.8.2  28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1  28-Apr-2008  martin file pthread_tsd.c was added on branch christos-time_t on 2008-04-28 20:23:02 +0000
 1.7.4.3  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.2  16-Jan-2013  yamt sync with (a bit old) head
 1.7.4.1  17-Apr-2012  yamt sync with head
 1.8.2.2  23-Jun-2013  tls resync from head
 1.8.2.1  25-Feb-2013  tls resync with head
 1.11.8.1  24-Nov-2015  martin Pull up following revision(s) (requested by manu in ticket #829):
lib/libpthread_dbg/pthread_dbg.c: revision 1.43 (via patch)
lib/libpthread/pthread_int.h: revision 1.91-1.92 (via patch)
lib/libc/stdlib/jemalloc.c: revision 1.37-1.38
lib/libpthread/pthread_tsd.c: revision 1.12-1.14 (via patch)
include/limits.h: revision 1.34 (via patch)
lib/libpthread/pthread.c: revision 1.146-1.147 (via patch)
lib/libpthread/pthread_key_create.3: revision 1.7 (via patch)

libpthread:

Make PTHREAD_KEYS_MAX dynamically adjustable
NetBSD's PTHREAD_KEYS_MAX is set to 256, which is low compared to
other systems like Linux (1024) or MacOS X (512). As a result some
setups tested on Linux will exhibit problems on NetBSD because of
pthread_keys usage beyond the limit. This happens for instance on
Apache with various module loaded, and in this case no particular
developper can be blamed for going beyond the limit, since several
modules from different sources contribute to the problem.
This patch makes the limit conigurable through the PTHREAD_KEYS_MAX
environement variable. If undefined, the default remains unchanged
(256). In any case, the value cannot be lowered below POSIX-mandated
_POSIX_THREAD_KEYS_MAX (128).

While there:
- use EXIT_FAILURE instead of 1 when calling err(3) in libpthread.
- Reset _POSIX_THREAD_KEYS_MAX to POSIX mandated 128, instead of 256.

Fix previous: Can't use calloc/malloc before we complete initialization
of the thread library, because malloc uses pthread_foo_specific, and it will
end up initializing itself incorrectly.

Thanks rump for not letting us use even mmap during initialization.

libc/jemalloc:

Fix non _REENTRANT build.
Defer using pthread keys until we are threaded.
From Christos, fixes PR port-arm/50087 by allowing malloc calls prior
to libpthread initialization.
 1.15.8.1  24-Jul-2017  snj Pull up following revision(s) (requested by kamil in ticket #119):
lib/libpthread/pthread_tsd.c: revision 1.16
PR/52386: Use the number of iterations we document.
 1.16.6.3  21-Apr-2020  martin Sync with HEAD
 1.16.6.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.16.6.1  10-Jun-2019  christos Sync with HEAD

RSS XML Feed