Make detached threads work better

This change adds a double linked list of threads, so that pthread_exit()
will know when it should call exit() from an orphaned child. This change
also improves ftrace and strace logging.
This commit is contained in:
Justine Tunney 2022-11-09 03:58:57 -08:00
parent b74d8c1acd
commit cee6871710
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
37 changed files with 638 additions and 314 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/internal.h"
#include "libc/calls/state.internal.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/extend.internal.h"
#include "libc/intrin/pushpop.h"
#include "libc/intrin/weaken.h"
@ -38,7 +39,7 @@ static textwindows dontinline void SetupWinStd(struct Fds *fds, int i, int x) {
if (!h || h == -1) return;
fds->p[i].kind = pushpop(kFdFile);
fds->p[i].handle = h;
fds->f = i + 1;
atomic_store_explicit(&fds->f, i + 1, memory_order_relaxed);
}
textstartup void InitializeFileDescriptors(void) {
@ -49,7 +50,7 @@ textstartup void InitializeFileDescriptors(void) {
fds = VEIL("r", &g_fds);
fds->p = fds->e = (void *)kMemtrackFdsStart;
fds->n = 4;
fds->f = 3;
atomic_store_explicit(&fds->f, 3, memory_order_relaxed);
fds->e = _extend(fds->p, fds->n * sizeof(*fds->p), fds->e, MAP_PRIVATE,
kMemtrackFdsStart + kMemtrackFdsSize);
if (IsMetal()) {