Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e7b988e

Browse files
authoredApr 4, 2023
Document the summary of two pthread implementations (bytecodealliance#2104)
And add `wasi-threads` to the key feature list in README.md.
1 parent 6af8785 commit e7b988e

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ WebAssembly Micro Runtime (WAMR) is a lightweight standalone WebAssembly (Wasm)
2929
- [The mechanism to export native APIs to Wasm applications](./doc/export_native_api.md), see [how to register native APIs](./doc/export_native_api.md)
3030
- [Multiple modules as dependencies](./doc/multi_module.md), ref to [document](./doc/multi_module.md) and [sample](samples/multi-module)
3131
- [Multi-thread, pthread APIs and thread management](./doc/pthread_library.md), ref to [document](./doc/pthread_library.md) and [sample](samples/multi-thread)
32+
- [wasi-threads](./doc/pthread_impls.md#wasi-threads-new), ref to [document](./doc/pthread_impls.md#wasi-threads-new) and [sample](samples/wasi-threads)
3233
- [Linux SGX (Intel Software Guard Extension) support](./doc/linux_sgx.md), ref to [document](./doc/linux_sgx.md)
3334
- [Source debugging support](./doc/source_debugging.md), ref to [document](./doc/source_debugging.md)
3435
- [XIP (Execution In Place) support](./doc/xip.md), ref to [document](./doc/xip.md)

‎doc/pthread_impls.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

‎doc/pthread_library.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# WAMR pthread library
22

3+
**Note**: This document describes the old pthread implementation.
4+
See [Pthread implementations](pthread_impls.md).
5+
36
WAMR provides a built-in library to support pthread APIs. You can call pthread APIs in your application source code.
47

58
## Build and run

0 commit comments

Comments
 (0)
Please sign in to comment.