cosmopolitan/third_party/nsync
Justine Tunney 624573207e
Make threads faster and more reliable
This change doubles the performance of thread spawning. That's thanks to
our new stack manager, which allows us to avoid zeroing stacks. It gives
us 15µs spawns rather than 30µs spawns on Linux. Also, pthread_exit() is
faster now, since it doesn't need to acquire the pthread GIL. On NetBSD,
that helps us avoid allocating too many semaphores. Even if that happens
we're now able to survive semaphores running out and even memory running
out, when allocating *NSYNC waiter objects. I found a lot more rare bugs
in the POSIX threads runtime that could cause things to crash, if you've
got dozens of threads all spawning and joining dozens of threads. I want
cosmo to be world class production worthy for 2025 so happy holidays all
2024-12-21 22:13:00 -08:00
..
mem Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
testing Make more Windows socket fixes and improvements 2024-09-18 20:29:42 -07:00
array.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
atomic.h Reduce header complexity 2023-11-28 14:39:42 -08:00
atomic.internal.h Make contended mutexes 30% faster on aarch64 2024-09-26 09:24:25 -07:00
BUILD.mk Introduce cosmo_futex_wait and cosmo_futex_wake 2024-11-22 11:25:15 -08:00
common.c Make threads faster and more reliable 2024-12-21 22:13:00 -08:00
common.internal.h Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
compat.S Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
counter.h Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
cv.h Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
debug.h Reduce header complexity 2023-11-28 14:39:42 -08:00
heap.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
LICENSE.txt Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
mu.c Make more fixups and quality assurance 2024-10-07 15:29:53 -07:00
mu.h Reduce header complexity 2023-11-28 14:39:42 -08:00
mu_semaphore.c Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
mu_semaphore.h Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
mu_semaphore.internal.h Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
mu_semaphore_futex.c Introduce cosmo_futex_wait and cosmo_futex_wake 2024-11-22 11:25:15 -08:00
mu_semaphore_sem.c Make threads faster and more reliable 2024-12-21 22:13:00 -08:00
mu_wait.h Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
note.h Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
notice.c Release Cosmopolitan v3.3 2024-02-20 13:27:59 -08:00
once.h Reduce header complexity 2023-11-28 14:39:42 -08:00
panic.c Eliminate cyclic locks in runtime 2024-12-16 22:25:12 -08:00
races.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
README.cosmo Make more fixups and quality assurance 2024-10-07 15:29:53 -07:00
time.c Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
time.h Delve into clock rabbit hole 2024-09-04 01:32:46 -07:00
wait_s.internal.h Reduce header complexity 2023-11-28 14:39:42 -08:00
waiter.h Introduce pthread_condattr_setclock() 2024-09-02 23:45:42 -07:00
yield.c Get rid of .internal.h convention in LIBC_INTRIN 2024-07-19 19:38:00 -07:00

DESCRIPTION

  *NSYNC is a synchronization primitives library.

LICENSE

  Apache 2.0

ORIGIN

  git@github.com:google/nsync
  commit ac5489682760393fe21bd2a8e038b528442412a7
  Author: Mike Burrows <m3b@google.com>
  Date:   Wed Jun 1 16:47:52 2022 -0700

LOCAL CHANGES

  - Fix nsync_mu_unlock() on Apple Silicon

  - Add clock parameter to many NSYNC wait APIs

  - Time APIs were so good that they're now in libc

  - Double linked list API was so good that it's now in libc

  - Max delay on sleep should be 20ms (not 4ms) on OpenBSD and NetBSD

  - Support Apple's ulock futexes which are internal but nicer than GCD

  - Ensure resources such as POSIX semaphores are are released on fork.

  - Make contended mutexes go 30% faster by using C11 atomics API. This
    lets us use weak cas when appropriate. It also avoids a superfluous
    relaxed load on failure. This mostly impacts aarch64, not x86_64.

  - Rewrote most of the semaphore and futex system call support code so
    it works well with Cosmopolitan's fat runtime portability. *NSYNC's
    unit test suite passes on all supported platforms. However the BSDs
    currently appear to be overutilizing CPU time compared with others.
    This appears to be the fault of the OSes rather than *NSYNC / Cosmo

  - Support POSIX thread cancellation. APIs that wait on condition vars
    are now cancellation points. In PTHREAD_CANCEL_MASKED mode they may
    return ECANCELED. In PTHREAD_CANCEL_DEFERRED mode the POSIX threads
    library will unwind the stack to re-acquire locks and free waiters.
    On the other hand the *NSYNC APIs for mutexes will now safely block
    thread cancellation, but you can still use *NSYNC notes to do that.