Skip to content

Commit 6e9df15

Browse files
committed
Implement single_threaded pthread_exit
Performs all the cancellation actions and then calls exit()
1 parent 90a21ba commit 6e9df15

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
381381
thread/pthread_barrierattr_destroy.c \
382382
thread/pthread_barrierattr_init.c \
383383
thread/pthread_barrierattr_setpshared.c \
384+
thread/pthread_cleanup_push.c \
384385
thread/pthread_cancel.c \
385386
thread/pthread_condattr_destroy.c \
386387
thread/pthread_condattr_init.c \

expected/wasm32-wasip1/defined-symbols.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ __cxa_finalize
3838
__default_guardsize
3939
__default_stacksize
4040
__des_setkey
41+
__do_cleanup_pop
42+
__do_cleanup_push
4143
__do_des
4244
__duplocale
4345
__env_rm_add
@@ -383,6 +385,8 @@ _environ
383385
_exit
384386
_flushlbf
385387
_initialize
388+
_pthread_cleanup_pop
389+
_pthread_cleanup_push
386390
_start
387391
a64l
388392
abort
@@ -982,6 +986,7 @@ pthread_condattr_setpshared
982986
pthread_create
983987
pthread_detach
984988
pthread_equal
989+
pthread_exit
985990
pthread_getspecific
986991
pthread_join
987992
pthread_key_create

libc-top-half/stub-pthreads/stub-pthreads.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ static void dummy_0()
55
}
66
weak_alias(dummy_0, __acquire_ptc);
77
weak_alias(dummy_0, __release_ptc);
8+
weak_alias(dummy_0, __pthread_tsd_run_dtors);
89

910
int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg)
1011
{
@@ -51,3 +52,27 @@ int pthread_once(pthread_once_t *control, void (*init)(void))
5152
}
5253
return 0;
5354
}
55+
56+
_Noreturn void pthread_exit(void *result)
57+
{
58+
/*
59+
We are the only thread, so when we exit the whole process exits.
60+
But we still have to run cancellation handlers...
61+
*/
62+
pthread_t self = __pthread_self();
63+
64+
self->canceldisable = 1;
65+
self->cancelasync = 0;
66+
self->result = result;
67+
68+
while (self->cancelbuf) {
69+
void (*f)(void *) = self->cancelbuf->__f;
70+
void *x = self->cancelbuf->__x;
71+
self->cancelbuf = self->cancelbuf->__next;
72+
f(x);
73+
}
74+
75+
__pthread_tsd_run_dtors();
76+
77+
exit(0);
78+
}

0 commit comments

Comments
 (0)