Skip to content

Commit

Permalink
Implement single_threaded pthread_exit
Browse files Browse the repository at this point in the history
This is "good" as it actually does perform
all the cancellation actions and then calls exit()
  • Loading branch information
ArcaneNibble committed Sep 25, 2024
1 parent fb73c1a commit 01a7f89
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,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 @@ -334,7 +335,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 @@ -380,6 +382,8 @@ _environ
_exit
_flushlbf
_initialize
_pthread_cleanup_pop
_pthread_cleanup_push
_start
a64l
abort
Expand Down Expand Up @@ -977,6 +981,7 @@ pthread_condattr_init
pthread_condattr_setclock
pthread_condattr_setpshared
pthread_equal
pthread_exit
pthread_getspecific
pthread_key_create
pthread_key_delete
Expand Down
5 changes: 5 additions & 0 deletions expected/wasm32-wasip2/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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 @@ -396,6 +398,8 @@ _environ
_exit
_flushlbf
_initialize
_pthread_cleanup_pop
_pthread_cleanup_push
_start
a64l
abort
Expand Down Expand Up @@ -1110,6 +1114,7 @@ pthread_condattr_init
pthread_condattr_setclock
pthread_condattr_setpshared
pthread_equal
pthread_exit
pthread_getspecific
pthread_key_create
pthread_key_delete
Expand Down
25 changes: 25 additions & 0 deletions stub-pthreads/stub-pthreads-good.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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_once(pthread_once_t *control, void (*init)(void))
{
Expand All @@ -16,3 +17,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 01a7f89

Please sign in to comment.