Skip to content

Commit

Permalink
fix: pthread_exit for WASI
Browse files Browse the repository at this point in the history
Can't use `exit()` because it is too high level.
Have to unlock the thread list.

Signed-off-by: Harald Hoyer <harald@profian.com>
  • Loading branch information
haraldh committed Oct 26, 2022
1 parent e755b1e commit 2f577a8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libc-top-half/musl/src/thread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ _Noreturn void __pthread_exit(void *result)
* and then exits without touching the stack. */
__unmapself(self->map_base, self->map_size);
}
#else
if (state==DT_DETACHED && self->map_base) {
// __syscall(SYS_exit) would unlock the thread, list
// do it manually here
__tl_unlock();
free(self->map_base);
// Can't use `exit()` here, because it is too high level
for (;;) __wasi_proc_exit(0);
}
#endif

/* Wake any joiner. */
Expand All @@ -197,7 +206,11 @@ _Noreturn void __pthread_exit(void *result)
#ifdef __wasilibc_unmodified_upstream
for (;;) __syscall(SYS_exit, 0);
#else
for (;;) exit(0);
// __syscall(SYS_exit) would unlock the thread, list
// do it manually here
__tl_unlock();
// Can't use `exit()` here, because it is too high level
for (;;) __wasi_proc_exit(0);
#endif
}

Expand Down

0 comments on commit 2f577a8

Please sign in to comment.