Commit 101782c
committed
wasi-threads: add an initial implementation
This change is a first step toward implementing `wasi-threads` in
Wasmtime. We may find that it has some missing pieces, but the core
functionality is there: when `wasi::thread_spawn` is called by a running
WebAssembly module, a function named `wasi_thread_start` is found in the
module's exports and called in a new instance. The shared memory of the
original instance is reused in the new instance.
This new WASI proposal is in its early stages and details are still
being hashed out in the [spec] and [wasi-libc] repositories. Due to its
experimental state, the `wasi-threads` functionality is hidden behind
both a compile-time and runtime flag: one must build with `--features
wasi-threads` but also run the Wasmtime CLI with `--wasm-features
threads` and `--wasi-modules experimental-wasi-threads`. One can
experiment with `wasi-threads` by running:
```console
$ cargo run --features wasi-threads -- \
--wasm-features threads --wasi-modules experimental-wasi-threads \
<a threads-enabled module>
```
Threads-enabled Wasm modules are not yet easy to build. Hopefully this
is resolved soon, but in the meantime see the use of
`THREAD_MODEL=posix` in the [wasi-libc] repository for some clues on
what is necessary. Wiggle complicates things by requiring the Wasm
memory to be exported with a certain name and `wasi-threads` also
expects that memory to be imported; this build-time obstacle can be
overcome with the `--import-memory --export-memory` flags only available
in the latest Clang tree. Due to all of this, the included tests are
written directly in WAT--run these with:
```console
$ cargo test --features wasi-threads -p wasmtime-cli -- cli_tests
```
[spec]: https://github.com/WebAssembly/wasi-threads
[wasi-libc]: https://github.com/WebAssembly/wasi-libc
This change does not protect the WASI implementations themselves from
concurrent access. This is already complete in previous commits or left
for future commits in certain cases (e.g., wasi-nn).1 parent 31c178e commit 101782c
File tree
10 files changed
+581
-41
lines changed- crates
- cli-flags/src
- wasi-threads
- src
- src/commands
- tests/all
- cli_tests
10 files changed
+581
-41
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| 128 | + | |
126 | 129 | | |
127 | 130 | | |
128 | 131 | | |
| |||
191 | 194 | | |
192 | 195 | | |
193 | 196 | | |
194 | | - | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
200 | 202 | | |
| 203 | + | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
53 | 57 | | |
54 | 58 | | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
58 | | - | |
59 | | - | |
| 62 | + | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
466 | 470 | | |
467 | 471 | | |
468 | 472 | | |
469 | | - | |
470 | 473 | | |
| 474 | + | |
| 475 | + | |
471 | 476 | | |
472 | 477 | | |
473 | 478 | | |
| |||
494 | 499 | | |
495 | 500 | | |
496 | 501 | | |
497 | | - | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
498 | 506 | | |
499 | 507 | | |
500 | | - | |
501 | | - | |
| 508 | + | |
| 509 | + | |
502 | 510 | | |
503 | 511 | | |
504 | 512 | | |
505 | 513 | | |
506 | 514 | | |
507 | 515 | | |
508 | | - | |
509 | 516 | | |
| 517 | + | |
| 518 | + | |
510 | 519 | | |
511 | 520 | | |
512 | 521 | | |
| |||
518 | 527 | | |
519 | 528 | | |
520 | 529 | | |
| 530 | + | |
521 | 531 | | |
522 | 532 | | |
523 | 533 | | |
| |||
663 | 673 | | |
664 | 674 | | |
665 | 675 | | |
| 676 | + | |
666 | 677 | | |
667 | | - | |
| 678 | + | |
668 | 679 | | |
669 | 680 | | |
670 | 681 | | |
| |||
676 | 687 | | |
677 | 688 | | |
678 | 689 | | |
| 690 | + | |
679 | 691 | | |
680 | | - | |
| 692 | + | |
681 | 693 | | |
682 | 694 | | |
683 | 695 | | |
| |||
693 | 705 | | |
694 | 706 | | |
695 | 707 | | |
| 708 | + | |
696 | 709 | | |
697 | | - | |
| 710 | + | |
698 | 711 | | |
699 | 712 | | |
700 | 713 | | |
| |||
707 | 720 | | |
708 | 721 | | |
709 | 722 | | |
| 723 | + | |
710 | 724 | | |
711 | | - | |
| 725 | + | |
712 | 726 | | |
713 | 727 | | |
714 | 728 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments