|
| 1 | +# Pthread implementations |
| 2 | + |
| 3 | +WAMR has two pthread implementations available as of writing this. |
| 4 | + |
| 5 | +These implementations are not ABI-compatible. You at least need to rebuild |
| 6 | +your wasm modules when migrating from one pthread implementation to another. |
| 7 | + |
| 8 | +For new users, we recommend to use (or at least experiment) |
| 9 | +the new wasi-threads based implementation. |
| 10 | +In future, we might remove the old implementation. |
| 11 | + |
| 12 | +## WAMR lib-pthread (old) |
| 13 | + |
| 14 | + * The pthread API is directly implemented as host functions in WAMR. |
| 15 | + (`WAMR_BUILD_LIB_PTHREAD`) |
| 16 | + |
| 17 | + * Only minimum API is implemented as of writing this. |
| 18 | + (eg. no pthread barriers) |
| 19 | + |
| 20 | + * WAMR-specific ABI |
| 21 | + |
| 22 | + * [Known limitations](pthread_library.md#known-limits) |
| 23 | + |
| 24 | +## wasi-threads (new) |
| 25 | + |
| 26 | + * The pthread API is implemented in wasi-libc, based on |
| 27 | + [wasi-threads](https://github.com/WebAssembly/wasi-threads) |
| 28 | + and [WASM threads](https://github.com/WebAssembly/threads) proposals. |
| 29 | + |
| 30 | + * It requires a recent-enough version of wasi-libc. The experimental support |
| 31 | + is included in |
| 32 | + [wasi-sdk 20.0](https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-20) |
| 33 | + or later. |
| 34 | + To build your application, cmake users can use the |
| 35 | + [cmake toolchain file](https://github.com/WebAssembly/wasi-sdk/blob/main/wasi-sdk-pthread.cmake) |
| 36 | + provided by wasi-sdk. |
| 37 | + |
| 38 | + * wasi-threads is implemented as a host function in WAMR. |
| 39 | + (`WAMR_BUILD_LIB_WASI_THREADS`) |
| 40 | + |
| 41 | + * The ABI is specified in wasi-threads proposal. |
| 42 | + You can run the same wasm modules on other runtimes which implement |
| 43 | + the proposal. (wasmtime, toywasm, ...) |
| 44 | + |
| 45 | + * Basically more feature-rich and complete than WAMR lib-pthread. |
| 46 | + |
| 47 | + **EXCEPTION**: `pthread_exit` is not available as of writing this. |
| 48 | + If `pthread_exit` is important for your use cases, please speak up in |
| 49 | + the [GitHub issue](https://github.com/WebAssembly/wasi-threads/issues/7). |
| 50 | + |
| 51 | + **EXCEPTION**: For threads created by `pthread_create`, the AUX stack |
| 52 | + (aka C shadow stack) overflow detection mechanism is disabled as of |
| 53 | + writing this. |
| 54 | + If it's important for your use cases, please speak up in the |
| 55 | + [GitHub issue](https://github.com/WebAssembly/wasi-threads/issues/12). |
| 56 | + |
| 57 | +# References |
| 58 | + |
| 59 | +* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1790 |
0 commit comments