Skip to content

Commit

Permalink
Implement single_threaded pthread_exit
Browse files Browse the repository at this point in the history
Performs all the cancellation actions and then calls exit()
  • Loading branch information
ArcaneNibble committed Aug 6, 2024
1 parent 70b21ea commit 38081ab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
thread/pthread_barrierattr_init.c \
thread/pthread_barrierattr_setpshared.c \
thread/pthread_cancel.c \
thread/pthread_cleanup_push.c \
thread/pthread_condattr_destroy.c \
thread/pthread_condattr_init.c \
thread/pthread_condattr_setclock.c \
Expand Down Expand Up @@ -332,7 +333,6 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
thread/pthread_barrier_destroy.c \
thread/pthread_barrier_init.c \
thread/pthread_barrier_wait.c \
thread/pthread_cleanup_push.c \
thread/pthread_cond_broadcast.c \
thread/pthread_cond_destroy.c \
thread/pthread_cond_init.c \
Expand Down
5 changes: 5 additions & 0 deletions expected/wasm32-wasip1/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ __cxa_finalize
__default_guardsize
__default_stacksize
__des_setkey
__do_cleanup_pop
__do_cleanup_push
__do_des
__duplocale
__env_rm_add
Expand Down Expand Up @@ -383,6 +385,8 @@ _environ
_exit
_flushlbf
_initialize
_pthread_cleanup_pop
_pthread_cleanup_push
_start
a64l
abort
Expand Down Expand Up @@ -982,6 +986,7 @@ pthread_condattr_setpshared
pthread_create
pthread_detach
pthread_equal
pthread_exit
pthread_getspecific
pthread_join
pthread_key_create
Expand Down
25 changes: 25 additions & 0 deletions libc-top-half/stub-pthreads/stub-pthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ static void dummy_0()
}
weak_alias(dummy_0, __acquire_ptc);
weak_alias(dummy_0, __release_ptc);
weak_alias(dummy_0, __pthread_tsd_run_dtors);

int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
{
Expand Down Expand Up @@ -51,3 +52,27 @@ int pthread_once(pthread_once_t *control, void (*init)(void))
}
return 0;
}

_Noreturn void pthread_exit(void *result)
{
/*
We are the only thread, so when we exit the whole process exits.
But we still have to run cancellation handlers...
*/
pthread_t self = __pthread_self();

self->canceldisable = 1;
self->cancelasync = 0;
self->result = result;

while (self->cancelbuf) {
void (*f)(void *) = self->cancelbuf->__f;
void *x = self->cancelbuf->__x;
self->cancelbuf = self->cancelbuf->__next;
f(x);
}

__pthread_tsd_run_dtors();

exit(0);
}

0 comments on commit 38081ab

Please sign in to comment.