You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/wasm_threads/README.md
+13-4Lines changed: 13 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -2,20 +2,22 @@
2
2
3
3
This is a port of [wasm_threads `simple.rs` example](https://github.com/chemicstry/wasm_thread/tree/main?tab=readme-ov-file#simple).
4
4
5
-
It should also work similarly with `wasm-bindgen-rayon` and `wasm-mt`.
5
+
It should also work similarly with `wasm-bindgen-rayon` and other packages that use SharedArrayBuffer.
6
+
7
+
An explanation of that approach is described [here](https://rustwasm.github.io/wasm-bindgen/examples/raytrace.html)
6
8
7
9
## Limitations
8
10
9
11
It has a few considerable advantages over the `webworker*` examples, but also considerable disadvantages.
10
12
11
-
For starters, `trunk serve` won't work currently, as it doesn't do Cross Site Isolation (setting 2 headers), which is [required for this approach to workers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements).
12
-
`sfz` works, with `cargo install sfz` and run `sfz dist --coi`in the root directory of this example, then click on index.html in the website directory.
13
+
For starters, this needs Cross Site Isolation (setting 2 headers), which is [required for this approach to workers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer#security_requirements).
14
+
We've added them in the trunk config.
13
15
14
16
These same headers are also required during deployment. Github pages does not allow setting headers, and alternatives such as using `<meta>` did not work in my testing, so these sites can't be deployed like that. Cloudflare Pages is a free alternative that allows setting headers that worked for me.
15
17
16
18
Then it also requires nightly Rust, because [the standard library needs to be rebuild](https://github.com/RReverser/wasm-bindgen-rayon?tab=readme-ov-file#building-rust-code).
17
19
18
-
Additional limitations are listed [here](https://github.com/chemicstry/wasm_thread/tree/7bc7dccebf2d96775b60bf0fda6b4173aa993aff?tab=readme-ov-file#notes-on-wasm-limitations).
20
+
Additional limitations are listed [here](https://rustwasm.github.io/wasm-bindgen/examples/raytrace.html#caveats) (some of them might be solved or worked around in libraries). Specifically for `wasm_thread` limitations are explained in the comments in the source code.
19
21
20
22
## Advantages
21
23
@@ -30,3 +32,10 @@ Additional limitations are listed [here](https://github.com/chemicstry/wasm_thre
30
32
Note that this requires the [toolchain file](./rust-toolchain.toml) and the [cargo config](.cargo/config.toml).
31
33
32
34
The `_headers` file and its copy in `index.html` is simply an example of how to set the headers using Cloudflare Pages.
35
+
36
+
If you get errors such as
37
+
38
+
> [Firefox] The WebAssembly.Memory object cannot be serialized. The Cross-Origin-Opener-Policy and Cross-Origin-Embedder-Policy HTTP headers can be used to enable this.
39
+
> [Chrome] SharedArrayBuffer transfer requires self.crossOriginIsolated.
40
+
41
+
Then the headers did not set correctly. You can check the response headers on the `/` file in the network tab of the browser developer tools.
0 commit comments