Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,21 @@ See [C setjmp/longjmp support] about setjmp/longjmp support.
[C setjmp/longjmp support]: SetjmpLongjmp.md

This repository experimentally supports __threads__ with
`--target=wasm32-wasi-threads`. It uses WebAssembly's [threads] primitives
`--target=wasm32-wasip1-threads`. It uses WebAssembly's [threads] primitives
(atomics, `wait`/`notify`, shared memory) and [wasi-threads] for spawning
threads. Note: this is experimental — do not expect long-term stability!

Note that the `pthread_*` family of functions, as well as C++ threading primitives
such as `<atomic>`, `<mutex>`, and `<thread>` are available on all targets.
Any attempt to spawn a thread will fail on `--target=wasm32-wasip1` or
`--target=wasm32-wasip2`, but other functionality, such as locks, still works.
This makes it easier to port C++ codebases, as only a fraction of code needs
to be modified to build for the single-threaded targets.

Defining a macro `_WASI_STRICT_PTHREAD` will make `pthread_create`,
`pthread_detach`, `pthread_join`, `pthread_tryjoin_np`, and `pthread_timedjoin_np`
fail with a compile time error when building for single-threaded targets.

[threads]: https://github.com/WebAssembly/threads
[wasi-threads]: https://github.com/WebAssembly/wasi-threads

Expand Down
10 changes: 4 additions & 6 deletions cmake/wasi-sdk-sysroot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,9 @@ execute_process(

function(define_libcxx_sub target target_suffix extra_target_flags extra_libdir_suffix)
if(${target} MATCHES threads)
set(threads ON)
set(pic OFF)
set(target_flags -pthread)
else()
set(threads OFF)
set(pic ON)
set(target_flags "")
endif()
Expand Down Expand Up @@ -262,8 +260,8 @@ function(define_libcxx_sub target target_suffix extra_target_flags extra_libdir_
-DCMAKE_STAGING_PREFIX=${wasi_sysroot}
-DCMAKE_POSITION_INDEPENDENT_CODE=${pic}
-DCXX_SUPPORTS_CXX11=ON
-DLIBCXX_ENABLE_THREADS:BOOL=${threads}
-DLIBCXX_HAS_PTHREAD_API:BOOL=${threads}
-DLIBCXX_ENABLE_THREADS:BOOL=ON
-DLIBCXX_HAS_PTHREAD_API:BOOL=ON
-DLIBCXX_HAS_EXTERNAL_THREAD_API:BOOL=OFF
-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF
-DLIBCXX_HAS_WIN32_THREAD_API:BOOL=OFF
Expand All @@ -280,8 +278,8 @@ function(define_libcxx_sub target target_suffix extra_target_flags extra_libdir_
-DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF
-DLIBCXXABI_ENABLE_SHARED:BOOL=${pic}
-DLIBCXXABI_SILENT_TERMINATE:BOOL=ON
-DLIBCXXABI_ENABLE_THREADS:BOOL=${threads}
-DLIBCXXABI_HAS_PTHREAD_API:BOOL=${threads}
-DLIBCXXABI_ENABLE_THREADS:BOOL=ON
-DLIBCXXABI_HAS_PTHREAD_API:BOOL=ON
-DLIBCXXABI_HAS_EXTERNAL_THREAD_API:BOOL=OFF
-DLIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF
-DLIBCXXABI_HAS_WIN32_THREAD_API:BOOL=OFF
Expand Down
2 changes: 1 addition & 1 deletion src/wasi-libc
Submodule wasi-libc updated 52 files
+33 −27 Makefile
+4 −3 expected/wasm32-wasip1/defined-symbols.txt
+4 −5 expected/wasm32-wasip1/predefined-macros.txt
+4 −3 expected/wasm32-wasip2/defined-symbols.txt
+4 −5 expected/wasm32-wasip2/predefined-macros.txt
+1 −1 libc-bottom-half/sources/preopens.c
+7 −18 libc-top-half/musl/include/pthread.h
+2 −2 libc-top-half/musl/include/unistd.h
+62 −0 libc-top-half/musl/src/string/memchr.c
+47 −0 libc-top-half/musl/src/string/strchrnul.c
+15 −15 libc-top-half/musl/src/string/strlen.c
+0 −16 stub-pthreads/README.md
+0 −23 stub-pthreads/barrier.c
+0 −36 stub-pthreads/condvar.c
+0 −67 stub-pthreads/mutex.c
+0 −60 stub-pthreads/rwlock.c
+0 −21 stub-pthreads/spinlock.c
+0 −40 stub-pthreads/stub-pthreads-emulated.c
+0 −43 stub-pthreads/stub-pthreads-good.c
+53 −0 test/src/misc/memchr.c
+58 −0 test/src/misc/strchrnul.c
+7 −0 thread-stub/README.md
+6 −0 thread-stub/pthread_barrier_destroy.c
+8 −0 thread-stub/pthread_barrier_init.c
+7 −0 thread-stub/pthread_barrier_wait.c
+6 −0 thread-stub/pthread_cond_broadcast.c
+6 −0 thread-stub/pthread_cond_destroy.c
+6 −0 thread-stub/pthread_cond_init.c
+6 −0 thread-stub/pthread_cond_signal.c
+13 −0 thread-stub/pthread_cond_timedwait.c
+9 −0 thread-stub/pthread_cond_wait.c
+19 −0 thread-stub/pthread_create.c
+13 −0 thread-stub/pthread_detach.c
+11 −0 thread-stub/pthread_getattr_np.c
+32 −0 thread-stub/pthread_join.c
+8 −0 thread-stub/pthread_mutex_consistent.c
+6 −0 thread-stub/pthread_mutex_getprioceiling.c
+21 −0 thread-stub/pthread_mutex_lock.c
+10 −0 thread-stub/pthread_mutex_timedlock.c
+21 −0 thread-stub/pthread_mutex_trylock.c
+10 −0 thread-stub/pthread_mutex_unlock.c
+12 −0 thread-stub/pthread_once.c
+11 −0 thread-stub/pthread_rwlock_rdlock.c
+8 −0 thread-stub/pthread_rwlock_timedrdlock.c
+8 −0 thread-stub/pthread_rwlock_timedwrlock.c
+11 −0 thread-stub/pthread_rwlock_tryrdlock.c
+10 −0 thread-stub/pthread_rwlock_trywrlock.c
+12 −0 thread-stub/pthread_rwlock_unlock.c
+10 −0 thread-stub/pthread_rwlock_wrlock.c
+8 −0 thread-stub/pthread_spin_lock.c
+8 −0 thread-stub/pthread_spin_trylock.c
+7 −0 thread-stub/pthread_spin_unlock.c
Loading