mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 08:18:30 +00:00
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
This commit is contained in:
parent
64c284003d
commit
60cb435cb4
124 changed files with 2169 additions and 718 deletions
12
third_party/dlmalloc/init.inc
vendored
12
third_party/dlmalloc/init.inc
vendored
|
@ -3,9 +3,9 @@
|
|||
/* ---------------------------- setting mparams -------------------------- */
|
||||
|
||||
#if LOCK_AT_FORK
|
||||
static void pre_fork(void) { ACQUIRE_LOCK(&(gm)->mutex); }
|
||||
static void post_fork_parent(void) { RELEASE_LOCK(&(gm)->mutex); }
|
||||
static void post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); }
|
||||
static void dlmalloc_pre_fork(void) { ACQUIRE_LOCK(&(gm)->mutex); }
|
||||
static void dlmalloc_post_fork_parent(void) { RELEASE_LOCK(&(gm)->mutex); }
|
||||
static void dlmalloc_post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); }
|
||||
#endif /* LOCK_AT_FORK */
|
||||
|
||||
/* Initialize mparams */
|
||||
|
@ -67,8 +67,11 @@ static int init_mparams(void) {
|
|||
gm->mflags = mparams.default_mflags;
|
||||
(void)INITIAL_LOCK(&gm->mutex);
|
||||
#endif
|
||||
|
||||
#if LOCK_AT_FORK
|
||||
pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child);
|
||||
pthread_atfork(&dlmalloc_pre_fork,
|
||||
&dlmalloc_post_fork_parent,
|
||||
&dlmalloc_post_fork_child);
|
||||
#endif
|
||||
|
||||
{
|
||||
|
@ -92,6 +95,7 @@ static int init_mparams(void) {
|
|||
}
|
||||
|
||||
RELEASE_MALLOC_GLOBAL_LOCK();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue