mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-23 22:02:27 +00:00
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:
parent
b74d8c1acd
commit
cee6871710
37 changed files with 638 additions and 314 deletions
|
@ -19,10 +19,13 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/thread/posixthread.internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "third_party/nsync/dll.h"
|
||||
|
||||
void OnUsr1(int sig, struct siginfo *si, void *vctx) {
|
||||
struct ucontext *ctx = vctx;
|
||||
|
@ -40,7 +43,6 @@ void TriggerSignal(void) {
|
|||
}
|
||||
|
||||
static void *Increment(void *arg) {
|
||||
ASSERT_EQ(EDEADLK, pthread_join(pthread_self(), 0));
|
||||
ASSERT_EQ(gettid(), pthread_getthreadid_np());
|
||||
TriggerSignal();
|
||||
return (void *)((uintptr_t)arg + 1);
|
||||
|
@ -50,6 +52,9 @@ TEST(pthread_detach, testCreateReturn) {
|
|||
pthread_t id;
|
||||
ASSERT_EQ(0, pthread_create(&id, 0, Increment, 0));
|
||||
ASSERT_EQ(0, pthread_detach(id));
|
||||
while (!pthread_orphan_np()) {
|
||||
pthread_decimate_np();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(pthread_detach, testDetachUponCreation) {
|
||||
|
@ -58,4 +63,7 @@ TEST(pthread_detach, testDetachUponCreation) {
|
|||
ASSERT_EQ(0, pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED));
|
||||
ASSERT_EQ(0, pthread_create(0, &attr, Increment, 0));
|
||||
ASSERT_EQ(0, pthread_attr_destroy(&attr));
|
||||
while (!pthread_orphan_np()) {
|
||||
pthread_decimate_np();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue