Make some fixups to POSIX threads

This commit is contained in:
Justine Tunney 2022-09-07 21:13:50 -07:00
parent de511bc71a
commit 6c323383e5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 168 additions and 69 deletions

View file

@ -17,12 +17,15 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/intrin/pthread.h"
#include "libc/mem/mem.h"
#include "libc/runtime/stack.h"
#include "libc/testlib/subprocess.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
#if 0
static void *Increment(void *arg) {
ASSERT_EQ(gettid(), pthread_getthreadid_np());
return (void *)((uintptr_t)arg + 1);
@ -98,3 +101,17 @@ TEST(pthread_detach, testCustomStack_withReallySmallSize) {
ASSERT_EQ(0, pthread_join(id, 0));
free(stk);
}
#endif
TEST(pthread_exit, mainThreadWorks) {
// _Exit1() can't set process exit code on XNU/NetBSD/OpenBSD.
if (IsLinux() || IsFreebsd() || IsWindows()) {
SPAWN(fork);
pthread_exit((void *)2);
EXITS(2);
} else {
SPAWN(fork);
pthread_exit((void *)0);
EXITS(0);
}
}