History log of /netbsd-src/lib/libpthread/pthread.c (Results 1 – 25 of 184)
Revision Date Author Comments
# ae29c597 08-Jun-2024 hannken <hannken@NetBSD.org>

Fix resource leak in pthread_create(). Pthread field "pt_lwpctl"
must not be accessed after _lwp_exit() as the kernel may free
it, attach it to another thread and change its "lc_curcpu".

The "pthre

Fix resource leak in pthread_create(). Pthread field "pt_lwpctl"
must not be accessed after _lwp_exit() as the kernel may free
it, attach it to another thread and change its "lc_curcpu".

The "pthread__deadqueue" will fill up with pthreads with
an invalid "pt_lwpctl" and allocated stack that never get
reused.

Replace the test "lc_curcpu == LWPCTL_CPU_EXITED" with
test "_lwp_kill(newthread->pt_lid, 0) == -1 && errno == ESRCH"
to make sure this thread has finished its _lwp_exit().

PR lib/57831 "Memory leaks in libpthread/libc"

show more ...


# 20941a42 28-Nov-2023 riastradh <riastradh@NetBSD.org>

pthread: Don't adjust user-allocated stack addresses by guardsize.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8


# 34013547 07-Sep-2023 ad <ad@NetBSD.org>

raise() has understood threads for a long time, don't reimplment it.


# a2c7f636 24-Mar-2023 joerg <joerg@NetBSD.org>

Use snprintf_ss in pthread__assertfunc and update comment in
pthread__errorfunc. snprintf can use locks in some code paths and we
only care about the restricted subset here.


# e3d96c2f 31-May-2022 riastradh <riastradh@NetBSD.org>

libpthread(3): Fix a marvellous interaction with rtld.

Patch from chs@. Comment explaining the story by me. This patch may
not be optimal -- maybe it would be better in pthread__init, or
better fo

libpthread(3): Fix a marvellous interaction with rtld.

Patch from chs@. Comment explaining the story by me. This patch may
not be optimal -- maybe it would be better in pthread__init, or
better for rtld to call _lwp_unpark after _lwp_park in the contened
case -- but we've tested this version and it's annoying to reproduce,
so let's take this version and worry about testing improvements
later.

show more ...


# 7adb4107 12-Feb-2022 riastradh <riastradh@NetBSD.org>

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 t

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.)

show more ...


# 98c521ff 13-Apr-2021 mrg <mrg@NetBSD.org>

fake-use alloca()'s return value to quieten -Werror=unused-result


# 984bb2b3 22-Jul-2020 msaitoh <msaitoh@NetBSD.org>

s/reseting/resetting/


# 6088a859 14-Jun-2020 ad <ad@NetBSD.org>

Don't need to ignore ESRCH from _lwp_park() any more.


# 30140ed2 11-Jun-2020 ad <ad@NetBSD.org>

Drop self->pt_lock before clearing TSD / malloc TSD.


# 62e0939e 10-Jun-2020 ad <ad@NetBSD.org>

- Make pthread_condvar and pthread_mutex work on the stack rather than in
pthread_t, so there's less chance of bad things happening if someone calls
(for example) pthread_cond_broadcast() from a

- Make pthread_condvar and pthread_mutex work on the stack rather than in
pthread_t, so there's less chance of bad things happening if someone calls
(for example) pthread_cond_broadcast() from a signal handler.

- Remove all the deferred waiter handling except for the one case that really
matters which is transferring waiters from condvar -> mutex on wakeup, and
do that by splicing the condvar's waiters onto the mutex.

- Remove the mutex waiters bit as it's another complication that's not
strictly needed.

show more ...


# 558a0c73 04-Jun-2020 joerg <joerg@NetBSD.org>

If _malloc_thread_cleanup is implement, call it from libpthread.
Provide the hook from modern jemalloc to avoid using TSD for the thread
destruction cleanup as it can result in reentrancy crashes if

If _malloc_thread_cleanup is implement, call it from libpthread.
Provide the hook from modern jemalloc to avoid using TSD for the thread
destruction cleanup as it can result in reentrancy crashes if fork is
called from a thread that never called malloc as it will result in a
late malloc from the pre-fork synchronisation handler.

show more ...


# 051faad4 03-Jun-2020 ad <ad@NetBSD.org>

Deal with a couple of problems with threads being awoken early due to
timeouts or cancellation where:

- The restarting thread calls _lwp_exit() before another thread gets around
to waking it with

Deal with a couple of problems with threads being awoken early due to
timeouts or cancellation where:

- The restarting thread calls _lwp_exit() before another thread gets around
to waking it with _lwp_unpark(), leading to ESRCH (observed by joerg@).
(I may have removed a similar check mistakenly over the weekend.)

- The restarting thread considers itself gone off the sleep queue but
at the same time another thread is part way through waking it, and hasn't
fully completed that operation yet by setting thread->pt_mutexwait = 0.
I think that could have potentially lead to the list of waiters getting
messed up given the right circumstances.

show more ...


# 34a4ae72 02-Jun-2020 joerg <joerg@NetBSD.org>

Pass down errno when calling pthread__errorfunc after a system call.
Allow format arguments for that reason and use (v)snprintf_ss in
pthread_errorfunc to avoid race conditions and the like.


# 06d492d1 01-Jun-2020 ad <ad@NetBSD.org>

In the interests of reliability simplify waiter handling more and redo
condvars to manage the list of waiters with atomic ops.


# bc77394c 16-May-2020 ad <ad@NetBSD.org>

- Try to eliminate a hang in "parked" I've been seeing while stress testing.
Centralise wakeup of deferred waiters in pthread__clear_waiters() and use
throughout libpthread. Make fewer assumptio

- Try to eliminate a hang in "parked" I've been seeing while stress testing.
Centralise wakeup of deferred waiters in pthread__clear_waiters() and use
throughout libpthread. Make fewer assumptions. Be more conservative in
pthread_mutex when dealing with pending waiters.

- Remove the "hint" argument everywhere since the kernel doesn't use it any
more.

show more ...


# 858ee362 15-May-2020 joerg <joerg@NetBSD.org>

Lock/unlock/reinit pthread__deadqueue_lock over fork.


# f3cc99ae 14-Apr-2020 joerg <joerg@NetBSD.org>

Drop most of the logic associated with pthread__started.

The pthread_cond logic is a questionable optimisation at best and the
post-fork logic is plainly broken.


# 331480e6 16-Feb-2020 kamil <kamil@NetBSD.org>

Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.


# bcfb2645 16-Feb-2020 kamil <kamil@NetBSD.org>

Set __isthreaded before bootstrapping malloc(3)

jemalloc depends on the __isthreaded dynamic state logic.

Reported by <wiz> for mpv and by <tih> for gzip.


# 5fa60982 15-Feb-2020 kamil <kamil@NetBSD.org>

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 r

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.

show more ...


# f66ccdf0 08-Feb-2020 kamil <kamil@NetBSD.org>

Change the behavior of pthread_equal()

On error when not aborting, do not return EINVAL as it has a side effect
of being interpreted as matching threads. For invalid threads return
unmatched.

Check

Change the behavior of pthread_equal()

On error when not aborting, do not return EINVAL as it has a side effect
of being interpreted as matching threads. For invalid threads return
unmatched.

Check pthreads for NULL, before accessing pt_magic field. This avoids
faults on comparision with a NULL pointer.

This behavior is in the scope of UB, but should be easier to deal with
buggy software.

show more ...


# 2da2192d 05-Feb-2020 ryoon <ryoon@NetBSD.org>

Remove trailing whiteapaces and tab


# fb0af629 29-Jan-2020 ad <ad@NetBSD.org>

- pthread_join(): remove temporary hack now kernel returns correct errno.

- kill(getpid(), SIGABRT) -> _lwp_kill(_lwp_self(), SIGABRT)


# 20668e14 29-Jan-2020 kamil <kamil@NetBSD.org>

Chack thread->pt_magic with PT_MAGIC promptly

Rearrange some checks to avoid verifying pthread_t after using it.


12345678