cosmopolitan/third_party/nsync
Justine Tunney 60cb435cb4
Implement pthread_atfork()
If threads are being used, then fork() will now acquire and release and
runtime locks so that fork() may be safely used from threads. This also
makes vfork() thread safe, because pthread mutexes will do nothing when
the process is a child of vfork(). More torture tests have been written
to confirm this all works like a charm. Additionally:

- Invent hexpcpy() api
- Rename nsync_malloc_() to kmalloc()
- Complete posix named semaphore implementation
- Make pthread_create() asynchronous signal safe
- Add rm, rmdir, and touch to command interpreter builtins
- Invent sigisprecious() and modify sigset functions to use it
- Add unit tests for posix_spawn() attributes and fix its bugs

One unresolved problem is the reclaiming of *NSYNC waiter memory in the
forked child processes, within apps which have threads waiting on locks
2022-10-16 12:25:13 -07:00
..
mem Elevate Windows production worthiness 2022-10-13 13:44:41 -07:00
testing Clean up some sleep code 2022-10-08 03:00:48 -07:00
array.internal.h Clean up some sleep code 2022-10-08 03:00:48 -07:00
atomic.h Optimize memory layout 2022-09-12 04:26:52 -07:00
atomic.internal.h Add shared memory apis to redbean 2022-10-06 04:55:26 -07:00
common.c Implement pthread_atfork() 2022-10-16 12:25:13 -07:00
common.internal.h Implement pthread_atfork() 2022-10-16 12:25:13 -07:00
compat.S Clean up some sleep code 2022-10-08 03:00:48 -07:00
counter.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
cv.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
debug.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
dll.c Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
dll.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
futex.c Implement pthread_atfork() 2022-10-16 12:25:13 -07:00
futex.internal.h Add posix semaphores support 2022-10-14 09:21:02 -07:00
heap.internal.h Clean up some sleep code 2022-10-08 03:00:48 -07:00
LICENSE.txt Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
mu.c Add *NSYNC mu_test 2022-09-11 18:56:29 -07:00
mu.h Pay off more technical debt 2022-09-12 23:36:56 -07:00
mu_semaphore.c Add posix semaphores support 2022-10-14 09:21:02 -07:00
mu_semaphore.h Improve the affinity system calls 2022-10-06 15:08:29 -07:00
mu_semaphore.internal.h Clean up some sleep code 2022-10-08 03:00:48 -07:00
mu_wait.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
note.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
nsync.mk Change support vector to Windows 8+ 2022-09-15 03:55:05 -07:00
once.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
panic.c Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
races.internal.h Add *NSYNC mu_test 2022-09-11 18:56:29 -07:00
README.cosmo Implement pthread_atfork() 2022-10-16 12:25:13 -07:00
README.md Add *NSYNC to libc/isystem 2022-09-13 01:47:12 -07:00
time.h Clean up some sleep code 2022-10-08 03:00:48 -07:00
wait_s.internal.h Add *NSYNC unit test suite 2022-10-07 21:34:15 -07:00
waiter.h Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
waiter_per_thread.c Use *NSYNC for POSIX threads locking APIs 2022-09-11 11:04:50 -07:00
yield.c Add *NSYNC unit test suite 2022-10-07 21:34:15 -07:00

*NSYNC

*NSYNC is a library providing scalable synchronization primitives. The following packages are provided:

  • THIRD_PARTY_NSYNC has nsync_mu which doesn't depend on malloc().
  • THIRD_PARTY_NSYNC_MEM has the rest of *NSYNC, e.g. nsync_cv.

The origin of this code is here:

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

NSYNC uses the Apache 2.0 license. We made the following local changes:

  • Write custom nsync_malloc_() so malloc() can use *NSYNC.

  • Rewrite futex() wrapper to support old Linux kernels and OpenBSD.

  • Normalize sources to Cosmopolitan style conventions; *NSYNC upstream supports dozens of compilers and operating systems, at compile-time. Since Cosmo solves portability at runtime instead, most of the build config toil has been removed, in order to help the NSYNC source code be more readable and hackable.