Skip to content

Commit b36b752

Browse files
authored
Disable pthread_exit for now (#366)
The current wasi-threads has no thread-exit functionality. Thus it isn't straightforward to implement pthread_exit without leaking thread context. This commit simply disables pthread_exit for now. Also, instead of abusing `wasi_proc_exit` for thread exit, make `wasi_thread_start` return. Note: `wasi_proc_exit` is supposed to terminate all threads in the "process", not only the calling thread. Note: Depending on the conclusion of the discussion about `wasi_thread_exit`, we might revisit this change later. References: WebAssembly/wasi-threads#7 WebAssembly/wasi-threads#17
1 parent 957c711 commit b36b752

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

expected/wasm32-wasi-pthread/defined-symbols.txt

-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ __progname
193193
__progname_full
194194
__pthread_cond_timedwait
195195
__pthread_create
196-
__pthread_exit
197196
__pthread_join
198197
__pthread_key_create
199198
__pthread_key_delete
@@ -1002,7 +1001,6 @@ pthread_condattr_setclock
10021001
pthread_condattr_setpshared
10031002
pthread_create
10041003
pthread_detach
1005-
pthread_exit
10061004
pthread_getspecific
10071005
pthread_join
10081006
pthread_key_create

libc-top-half/musl/include/pthread.h

+2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ extern "C" {
8585

8686
int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict);
8787
int pthread_detach(pthread_t);
88+
#ifdef __wasilibc_unmodified_upstream
8889
_Noreturn void pthread_exit(void *);
90+
#endif
8991
int pthread_join(pthread_t, void **);
9092

9193
#ifdef __GNUC__

libc-top-half/musl/src/include/pthread.h

+2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ hidden int __pthread_once(pthread_once_t *, void (*)(void));
77
hidden void __pthread_testcancel(void);
88
hidden int __pthread_setcancelstate(int, int *);
99
hidden int __pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict);
10+
#ifdef __wasilibc_unmodified_upstream
1011
hidden _Noreturn void __pthread_exit(void *);
12+
#endif
1113
hidden int __pthread_join(pthread_t, void **);
1214
hidden int __pthread_mutex_lock(pthread_mutex_t *);
1315
hidden int __pthread_mutex_trylock(pthread_mutex_t *);

libc-top-half/musl/src/thread/pthread_create.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ void __tl_sync(pthread_t td)
6060
if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0);
6161
}
6262

63+
#ifdef __wasilibc_unmodified_upstream
6364
_Noreturn void __pthread_exit(void *result)
65+
#else
66+
static void __pthread_exit(void *result)
67+
#endif
6468
{
6569
pthread_t self = __pthread_self();
6670
sigset_t set;
@@ -191,7 +195,7 @@ _Noreturn void __pthread_exit(void *result)
191195
__tl_unlock();
192196
free(self->map_base);
193197
// Can't use `exit()` here, because it is too high level
194-
for (;;) __wasi_proc_exit(0);
198+
return;
195199
}
196200
#endif
197201

@@ -212,7 +216,6 @@ _Noreturn void __pthread_exit(void *result)
212216
// do it manually here
213217
__tl_unlock();
214218
// Can't use `exit()` here, because it is too high level
215-
for (;;) __wasi_proc_exit(0);
216219
#endif
217220
}
218221

@@ -272,7 +275,7 @@ static int start_c11(void *p)
272275
}
273276
#else
274277
__attribute__((export_name("wasi_thread_start")))
275-
_Noreturn void wasi_thread_start(int tid, void *p)
278+
void wasi_thread_start(int tid, void *p)
276279
{
277280
struct start_args *args = p;
278281
__asm__(".globaltype __tls_base, i32\n"
@@ -570,5 +573,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
570573
return EAGAIN;
571574
}
572575

576+
#ifdef __wasilibc_unmodified_upstream
573577
weak_alias(__pthread_exit, pthread_exit);
578+
#endif
574579
weak_alias(__pthread_create, pthread_create);

0 commit comments

Comments
 (0)