forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasi-threads: add an initial implementation (WIP)
This change demonstrates a first step at how `wasi-threads` might be implemented in Wasmtime. It has hacks (described below), so it should only be consided a highly-experimental, use-at-your-own-risk work in progress. The included test file can be run with the following incantation (the `+nightly` is to allow the `Arc`-mutation hack): ``` cargo +nightly run -p wasmtime-cli --features wasi-threads -- \ tests/all/cli_tests/threads.wat \ --wasm-features threads --wasi-modules experimental-wasi-threads ``` Implementing this highlights two large issues still to be resolved: - _`Host` sharing_: the approach taken here is to clone the `Linker` so that `wasi-threads` has a separate version of it and to share the `Host` among threads using an `Arc<Host>`. This does nothing to protect the `Host` state from concurrent access--which it must be in a future iteration of this. This could be done with, e.g., a `Mutex` per WASI proposal, preventing any concurrent access for any method in that proposal, but unfortunately the signature of `get_cx` prevents me from using the `MutexGuard`. Some more refactoring and thinking is necessary here; suggestions welcome. - _Guest code traps_: this change has no way to recover from traps in the user function and return control to the thread entry point, which may be responsible for clean up (e.g., in C, `notify` any `pthread_join`ers that execution is complete). Note that the associated CLI test fails, but probably just due to my misunderstanding how to correctly tell the WAT library to enable the threads proposal: ``` cargo +nightly test --features wasi-threads -p wasmtime-cli -- cli_tests ```
- Loading branch information
Showing
11 changed files
with
561 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[package] | ||
name = "wasmtime-wasi-threads" | ||
version.workspace = true | ||
authors.workspace = true | ||
description = "Wasmtime implementation of the wasi-threads API" | ||
documentation = "https://docs.rs/wasmtime-wasi-nn" | ||
license = "Apache-2.0 WITH LLVM-exception" | ||
categories = ["wasm", "parallelism", "threads"] | ||
keywords = ["webassembly", "wasm", "neural-network"] | ||
repository = "https://github.com/bytecodealliance/wasmtime" | ||
readme = "README.md" | ||
edition.workspace = true | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
log = { workspace = true } | ||
rand = "0.8" | ||
wasmtime = { workspace = true } | ||
|
||
[badges] | ||
maintenance = { status = "experimental" } |
Oops, something went wrong.