Skip to content

Commit 3f7eb4c

Browse files
authored
Refactor stub pthread library and enable unconditionally (#602)
This PR changes the layout of the stub pthread library to match that of libc-top-half: splits it into (mostly) one file per function, and ensures the same API is exposed from both libraries, adding stub functions as necessary. This PR also removes `-lwasi-emulated-pthread` as well as `-D_WASI_EMULATED_PTHREAD` and enables this functionality unconditionally, seeing as this is necessary for building libc++ with threading enabled. It adds a flag `-D_WASI_STRICT_PTHREAD` that causes thread creation functions (`pthread_create`, `pthread_detach`, `pthread_join`) to be defined as a macro causing a compile error, which can be used to locate the parts of a codebase requiring changes for the single thread model. Specifically, after this commit, the two targets `wasm32-wasip1` and `wasm32-wasip1-threads` differ as follows (cleaned up for clarity): ```diff --- expected/wasm32-wasip1/defined-symbols.txt +++ expected/wasm32-wasip1-threads/defined-symbols.txt +flockfile +ftrylockfile +funlockfile +sem_destroy +sem_getvalue +sem_init +sem_post +sem_timedwait +sem_trywait +sem_wait +wasi_thread_start ``` ```diff --- expected/wasm32-wasip1/predefined-macros.txt +++ expected/wasm32-wasip1-threads/predefined-macros.txt +#define _REENTRANT 1 +#define SEM_NSEMS_MAX 256 +#define SEM_VALUE_MAX 0x7fffffff +#define __wasm_atomics__ 1 +#define __wasm_bulk_memory__ 1 ```
1 parent db46bf7 commit 3f7eb4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+388
-369
lines changed

Makefile

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ DLMALLOC_SOURCES = $(DLMALLOC_SRC_DIR)/dlmalloc.c
7171
DLMALLOC_INC = $(DLMALLOC_DIR)/include
7272
EMMALLOC_DIR = emmalloc
7373
EMMALLOC_SOURCES = $(EMMALLOC_DIR)/emmalloc.c
74-
STUB_PTHREADS_DIR = stub-pthreads
74+
THREAD_STUB_DIR = thread-stub
7575
LIBC_BOTTOM_HALF_DIR = libc-bottom-half
7676
LIBC_BOTTOM_HALF_CLOUDLIBC_SRC = $(LIBC_BOTTOM_HALF_DIR)/cloudlibc/src
7777
LIBC_BOTTOM_HALF_CLOUDLIBC_SRC_INC = $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/include
@@ -138,8 +138,6 @@ LIBWASI_EMULATED_SIGNAL_SOURCES = \
138138
LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES = \
139139
$(LIBC_TOP_HALF_MUSL_SRC_DIR)/signal/psignal.c \
140140
$(LIBC_TOP_HALF_MUSL_SRC_DIR)/string/strsignal.c
141-
LIBWASI_EMULATED_PTHREAD_SOURCES = \
142-
$(STUB_PTHREADS_DIR)/stub-pthreads-emulated.c
143141
LIBDL_SOURCES = $(LIBC_TOP_HALF_MUSL_SRC_DIR)/misc/dl.c
144142
LIBSETJMP_SOURCES = $(LIBC_TOP_HALF_MUSL_SRC_DIR)/setjmp/wasm32/rt.c
145143
LIBC_BOTTOM_HALF_CRT_SOURCES = $(wildcard $(LIBC_BOTTOM_HALF_DIR)/crt/*.c)
@@ -373,12 +371,38 @@ endif
373371
ifeq ($(THREAD_MODEL), single)
374372
# pthreads stubs for single-threaded environment
375373
LIBC_TOP_HALF_MUSL_SOURCES += \
376-
$(STUB_PTHREADS_DIR)/barrier.c \
377-
$(STUB_PTHREADS_DIR)/condvar.c \
378-
$(STUB_PTHREADS_DIR)/mutex.c \
379-
$(STUB_PTHREADS_DIR)/rwlock.c \
380-
$(STUB_PTHREADS_DIR)/spinlock.c \
381-
$(STUB_PTHREADS_DIR)/stub-pthreads-good.c
374+
$(addprefix $(THREAD_STUB_DIR)/, \
375+
pthread_barrier_destroy.c \
376+
pthread_barrier_init.c \
377+
pthread_barrier_wait.c \
378+
pthread_cond_broadcast.c \
379+
pthread_cond_destroy.c \
380+
pthread_cond_init.c \
381+
pthread_cond_signal.c \
382+
pthread_cond_timedwait.c \
383+
pthread_cond_wait.c \
384+
pthread_create.c \
385+
pthread_detach.c \
386+
pthread_getattr_np.c \
387+
pthread_join.c \
388+
pthread_mutex_consistent.c \
389+
pthread_mutex_getprioceiling.c \
390+
pthread_mutex_lock.c \
391+
pthread_mutex_timedlock.c \
392+
pthread_mutex_trylock.c \
393+
pthread_mutex_unlock.c \
394+
pthread_once.c \
395+
pthread_rwlock_rdlock.c \
396+
pthread_rwlock_timedrdlock.c \
397+
pthread_rwlock_timedwrlock.c \
398+
pthread_rwlock_tryrdlock.c \
399+
pthread_rwlock_trywrlock.c \
400+
pthread_rwlock_unlock.c \
401+
pthread_rwlock_wrlock.c \
402+
pthread_spin_lock.c \
403+
pthread_spin_trylock.c \
404+
pthread_spin_unlock.c \
405+
)
382406
endif
383407

384408
MUSL_PRINTSCAN_SOURCES = \
@@ -505,7 +529,6 @@ LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS = $(call objs,$(LIBWASI_EMULATED_PROCESS_CL
505529
LIBWASI_EMULATED_GETPID_OBJS = $(call objs,$(LIBWASI_EMULATED_GETPID_SOURCES))
506530
LIBWASI_EMULATED_SIGNAL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_SOURCES))
507531
LIBWASI_EMULATED_SIGNAL_MUSL_OBJS = $(call objs,$(LIBWASI_EMULATED_SIGNAL_MUSL_SOURCES))
508-
LIBWASI_EMULATED_PTHREAD_OBJS = $(call objs,$(LIBWASI_EMULATED_PTHREAD_SOURCES))
509532
LIBDL_OBJS = $(call objs,$(LIBDL_SOURCES))
510533
LIBSETJMP_OBJS = $(call objs,$(LIBSETJMP_SOURCES))
511534
LIBC_BOTTOM_HALF_CRT_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_CRT_SOURCES))
@@ -529,7 +552,6 @@ LIBWASI_EMULATED_PROCESS_CLOCKS_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULA
529552
LIBWASI_EMULATED_GETPID_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULATED_GETPID_OBJS))
530553
LIBWASI_EMULATED_SIGNAL_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULATED_SIGNAL_OBJS))
531554
LIBWASI_EMULATED_SIGNAL_MUSL_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS))
532-
LIBWASI_EMULATED_PTHREAD_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBWASI_EMULATED_PTHREAD_OBJS))
533555
LIBDL_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBDL_OBJS))
534556
LIBSETJMP_SO_OBJS = $(patsubst %.o,%.pic.o,$(LIBSETJMP_OBJS))
535557
BULK_MEMORY_SO_OBJS = $(patsubst %.o,%.pic.o,$(BULK_MEMORY_OBJS))
@@ -546,7 +568,6 @@ PIC_OBJS = \
546568
$(LIBWASI_EMULATED_GETPID_SO_OBJS) \
547569
$(LIBWASI_EMULATED_SIGNAL_SO_OBJS) \
548570
$(LIBWASI_EMULATED_SIGNAL_MUSL_SO_OBJS) \
549-
$(LIBWASI_EMULATED_PTHREAD_SO_OBJS) \
550571
$(LIBDL_SO_OBJS) \
551572
$(LIBSETJMP_SO_OBJS) \
552573
$(BULK_MEMORY_SO_OBJS) \
@@ -646,8 +667,6 @@ $(OBJDIR)/libwasi-emulated-getpid.so.a: $(LIBWASI_EMULATED_GETPID_SO_OBJS)
646667

647668
$(OBJDIR)/libwasi-emulated-signal.so.a: $(LIBWASI_EMULATED_SIGNAL_SO_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_SO_OBJS)
648669

649-
$(OBJDIR)/libwasi-emulated-pthread.so.a: $(LIBWASI_EMULATED_PTHREAD_SO_OBJS)
650-
651670
$(OBJDIR)/libdl.so.a: $(LIBDL_SO_OBJS)
652671

653672
$(OBJDIR)/libsetjmp.so.a: $(LIBSETJMP_SO_OBJS)
@@ -666,8 +685,6 @@ $(SYSROOT_LIB)/libwasi-emulated-getpid.a: $(LIBWASI_EMULATED_GETPID_OBJS)
666685

667686
$(SYSROOT_LIB)/libwasi-emulated-signal.a: $(LIBWASI_EMULATED_SIGNAL_OBJS) $(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS)
668687

669-
$(SYSROOT_LIB)/libwasi-emulated-pthread.a: $(LIBWASI_EMULATED_PTHREAD_OBJS)
670-
671688
$(SYSROOT_LIB)/libdl.a: $(LIBDL_OBJS)
672689

673690
$(SYSROOT_LIB)/libsetjmp.a: $(LIBSETJMP_OBJS)
@@ -770,12 +787,6 @@ $(FTS_OBJS) $(FTS_SO_OBJS): CFLAGS += \
770787
$(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS) $(LIBWASI_EMULATED_PROCESS_CLOCKS_SO_OBJS): CFLAGS += \
771788
-I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)
772789

773-
$(LIBWASI_EMULATED_PTHREAD_OBJS) $(LIBWASI_EMULATED_PTHREAD_SO_OBJS): CFLAGS += \
774-
-I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/include \
775-
-I$(LIBC_TOP_HALF_MUSL_SRC_DIR)/internal \
776-
-I$(LIBC_TOP_HALF_MUSL_DIR)/arch/wasm32 \
777-
-D_WASI_EMULATED_PTHREAD
778-
779790
# emmalloc uses a lot of pointer type-punning, which is UB under strict aliasing,
780791
# and this was found to have real miscompilations in wasi-libc#421.
781792
$(EMMALLOC_OBJS): CFLAGS += \
@@ -816,7 +827,6 @@ LIBC_SO = \
816827
$(SYSROOT_LIB)/libwasi-emulated-process-clocks.so \
817828
$(SYSROOT_LIB)/libwasi-emulated-getpid.so \
818829
$(SYSROOT_LIB)/libwasi-emulated-signal.so \
819-
$(SYSROOT_LIB)/libwasi-emulated-pthread.so \
820830
$(SYSROOT_LIB)/libdl.so
821831
ifeq ($(BUILD_LIBSETJMP),yes)
822832
LIBC_SO += \
@@ -835,10 +845,6 @@ STATIC_LIBS = \
835845
$(SYSROOT_LIB)/libwasi-emulated-getpid.a \
836846
$(SYSROOT_LIB)/libwasi-emulated-signal.a \
837847
$(SYSROOT_LIB)/libdl.a
838-
ifneq ($(THREAD_MODEL), posix)
839-
STATIC_LIBS += \
840-
$(SYSROOT_LIB)/libwasi-emulated-pthread.a
841-
endif
842848
ifeq ($(BUILD_LIBSETJMP),yes)
843849
STATIC_LIBS += \
844850
$(SYSROOT_LIB)/libsetjmp.a

expected/wasm32-wasip1/defined-symbols.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,14 @@ __progname
182182
__progname_full
183183
__pthread_cond_timedwait
184184
__pthread_create
185-
__pthread_detach
186185
__pthread_join
187186
__pthread_key_create
188187
__pthread_key_delete
189-
__pthread_mutex_consistent
190188
__pthread_mutex_lock
191189
__pthread_mutex_timedlock
192190
__pthread_mutex_trylock
193191
__pthread_mutex_unlock
192+
__pthread_once
194193
__pthread_rwlock_rdlock
195194
__pthread_rwlock_timedrdlock
196195
__pthread_rwlock_timedwrlock
@@ -991,13 +990,14 @@ pthread_condattr_setpshared
991990
pthread_create
992991
pthread_detach
993992
pthread_equal
994-
pthread_exit
993+
pthread_getattr_np
995994
pthread_getspecific
996995
pthread_join
997996
pthread_key_create
998997
pthread_key_delete
999998
pthread_mutex_consistent
1000999
pthread_mutex_destroy
1000+
pthread_mutex_getprioceiling
10011001
pthread_mutex_init
10021002
pthread_mutex_lock
10031003
pthread_mutex_timedlock
@@ -1221,6 +1221,7 @@ tgamma
12211221
tgammaf
12221222
tgammal
12231223
thrd_current
1224+
thrd_detach
12241225
thrd_equal
12251226
thrd_sleep
12261227
time

expected/wasm32-wasip1/predefined-macros.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,8 +2252,12 @@
22522252
#define _POSIX_STREAM_MAX 8
22532253
#define _POSIX_SYMLINK_MAX 255
22542254
#define _POSIX_SYMLOOP_MAX 8
2255+
#define _POSIX_THREADS _POSIX_VERSION
2256+
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
22552257
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
22562258
#define _POSIX_THREAD_KEYS_MAX 128
2259+
#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
2260+
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
22572261
#define _POSIX_THREAD_THREADS_MAX 64
22582262
#define _POSIX_TIMEOUTS _POSIX_VERSION
22592263
#define _POSIX_TIMERS _POSIX_VERSION
@@ -3430,12 +3434,7 @@
34303434
#define preadv64 preadv
34313435
#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
34323436
#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
3433-
#define pthread_create(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
3434-
#define pthread_detach(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
34353437
#define pthread_equal(x,y) ((x)==(y))
3436-
#define pthread_join(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
3437-
#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
3438-
#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
34393438
#define pwrite64 pwrite
34403439
#define pwritev64 pwritev
34413440
#define readdir64 readdir

expected/wasm32-wasip2/defined-symbols.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,14 @@ __progname
185185
__progname_full
186186
__pthread_cond_timedwait
187187
__pthread_create
188-
__pthread_detach
189188
__pthread_join
190189
__pthread_key_create
191190
__pthread_key_delete
192-
__pthread_mutex_consistent
193191
__pthread_mutex_lock
194192
__pthread_mutex_timedlock
195193
__pthread_mutex_trylock
196194
__pthread_mutex_unlock
195+
__pthread_once
197196
__pthread_rwlock_rdlock
198197
__pthread_rwlock_timedrdlock
199198
__pthread_rwlock_timedwrlock
@@ -1127,13 +1126,14 @@ pthread_condattr_setpshared
11271126
pthread_create
11281127
pthread_detach
11291128
pthread_equal
1130-
pthread_exit
1129+
pthread_getattr_np
11311130
pthread_getspecific
11321131
pthread_join
11331132
pthread_key_create
11341133
pthread_key_delete
11351134
pthread_mutex_consistent
11361135
pthread_mutex_destroy
1136+
pthread_mutex_getprioceiling
11371137
pthread_mutex_init
11381138
pthread_mutex_lock
11391139
pthread_mutex_timedlock
@@ -1457,6 +1457,7 @@ tgamma
14571457
tgammaf
14581458
tgammal
14591459
thrd_current
1460+
thrd_detach
14601461
thrd_equal
14611462
thrd_sleep
14621463
time

expected/wasm32-wasip2/predefined-macros.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2403,8 +2403,12 @@
24032403
#define _POSIX_STREAM_MAX 8
24042404
#define _POSIX_SYMLINK_MAX 255
24052405
#define _POSIX_SYMLOOP_MAX 8
2406+
#define _POSIX_THREADS _POSIX_VERSION
2407+
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
24062408
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
24072409
#define _POSIX_THREAD_KEYS_MAX 128
2410+
#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
2411+
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
24082412
#define _POSIX_THREAD_THREADS_MAX 64
24092413
#define _POSIX_TIMEOUTS _POSIX_VERSION
24102414
#define _POSIX_TIMERS _POSIX_VERSION
@@ -3585,12 +3589,7 @@
35853589
#define preadv64 preadv
35863590
#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
35873591
#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
3588-
#define pthread_create(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
3589-
#define pthread_detach(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
35903592
#define pthread_equal(x,y) ((x)==(y))
3591-
#define pthread_join(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
3592-
#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
3593-
#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; to enable stub functions which always fail, compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
35943593
#define pwrite64 pwrite
35953594
#define pwritev64 pwritev
35963595
#define readdir64 readdir

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,14 @@ int pthread_detach(pthread_t);
8383
_Noreturn void pthread_exit(void *);
8484
int pthread_join(pthread_t, void **);
8585
#else
86-
#if defined(_WASI_EMULATED_PTHREAD) || defined(_REENTRANT)
86+
#if defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD)
8787
int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict);
8888
int pthread_detach(pthread_t);
8989
int pthread_join(pthread_t, void **);
9090
#else
91-
#include <assert.h>
92-
#define pthread_create(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
93-
to enable stub functions which always fail, \
94-
compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
95-
#define pthread_detach(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
96-
to enable stub functions which always fail, \
97-
compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
98-
#define pthread_join(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
99-
to enable stub functions which always fail, \
100-
compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
91+
#define pthread_create(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;})
92+
#define pthread_detach(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;})
93+
#define pthread_join(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;})
10194
#endif
10295
#endif
10396

@@ -249,16 +242,12 @@ int pthread_setname_np(pthread_t, const char *);
249242
int pthread_getname_np(pthread_t, char *, size_t);
250243
int pthread_getattr_default_np(pthread_attr_t *);
251244
int pthread_setattr_default_np(const pthread_attr_t *);
252-
#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PTHREAD) || defined(_REENTRANT)
245+
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD)
253246
int pthread_tryjoin_np(pthread_t, void **);
254247
int pthread_timedjoin_np(pthread_t, void **, const struct timespec *);
255248
#else
256-
#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
257-
to enable stub functions which always fail, \
258-
compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
259-
#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This mode of WASI does not have threads enabled; \
260-
to enable stub functions which always fail, \
261-
compile with -D_WASI_EMULATED_PTHREAD and link with -lwasi-emulated-pthread"); 0;})
249+
#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;})
250+
#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;})
262251
#endif
263252
#endif
264253

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ pid_t gettid(void);
336336
#endif
337337
#define _POSIX_VDISABLE 0
338338

339-
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
339+
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD)
340340
#define _POSIX_THREADS _POSIX_VERSION
341341
#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION
342342
#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION
343343
#endif
344344
#if defined(__wasilibc_unmodified_upstream) /* wasi-libc doesn't provide pthread_attr_{get,set}stackaddr */
345345
#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION
346346
#endif
347-
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
347+
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD)
348348
#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION
349349
#endif
350350
#if defined(__wasilibc_unmodified_upstream) /* WASI has no scheduling control, and wasi-libc doesn't provide pthread_getcpuclockid */

stub-pthreads/README.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

stub-pthreads/barrier.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)