This is an example project of how to use threads in C++ with WebAssembly and how to communicate between the C++ and JavaScript worlds with Embind.
- Install cmake.
- Install and initialize the Emscripten SDK from https://emscripten.org.
- Then:
mandelbrot-wasm # mkdir build
mandelbrot-wasm # cd build
build # emcmake cmake ..
build # make
build # emrun --port 8000 --no_browser .
- Point your browser to http://localhost:8000/www/index.html
Unfortunately. mobile browsers currently do not support running multi-threaded WebAssembly. Sorry!
Chrome/Chromium 68 or higher is required.
https://www.chromium.org/Home/chromium-security/ssca
Edge 79 or higher is required.
TL;DR: It won't run in Firefox right now. Mozilla is working to fix it (since 2018...).
Due to several security enforcements, Firefox is currently (Firefox 77) still unable to run multi-threaded WebAssembly.
-
Because of the Spectre vulnerability, Firefox (temporarily?) disabled support for
SharedArrayBuffer
in 2018. This effectively disables the use of multi-threaded WebAssembly.https://blog.mozilla.org/security/2018/01/03/mitigations-landing-new-class-timing-attack/
It can be enabled (with the risk of Spectre vulnerability) in
about:config
:javascript.options.shared_memory = true
Enable at your own risk.
-
Further enforcement are in place, too, making life hard.
-
You might have a better chance of running this code in Firefox Nightly.