Details
-
Task
-
Resolution: Done
-
P2: Important
-
None
-
None
Description
Working multithreading requires support in the browsers, in Emscripten, and in Qt.
Thread support in browsers is starting to come back after SPECTRE, and can often be enabled in the browser settings for development purposes.
Emscripten has a “USE_PTHREADS=1” build mode which enables threads. This mode somewhat less stable than the default mode, with some limitations. See https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
Qt already supports threads, so what we need to do here is set the required Emscripten options and make sure we use the Emscripten API correctly.
Patch for enabling USE_PTHREADS for Qt: WebAssembly: implement thread support
Specific Emscripten bugs and limitations hit by Qt include:
- Qt Quick apps miscompiles: https://github.com/WebAssembly/binaryen/issues/1718
- Can’t use the MODULARIZE feature: https://github.com/kripken/emscripten/issues/7448
- The ALLOW_MEMORY_GROWTH flag is not supported: Qt must hardcode how much memory the app should use, and the amount is then allocated on startup. Browsers limit this startup allocation to 1 GB. https://github.com/kripken/emscripten/issues/7110
Prototype (outdated)
https://github.com/msorvig/qt-webassembly-examples/tree/master/emscripten_pthreads
Learnings relevant to the Qt port:
- Enable by setting USE_PTHREADS = 1 or USE_PTHREADS = 2
- USE_PTHREADS=2 enables run-time pthread support detection, allowing compiling a single binary for both thread/no-thread. However, it looks like the generated module.js will use javascript Atomics unconditionally, which may defeat this feature since browsers (at least firefox) disables Atomics along with SharedArrayBuffer.
- There's a ripple effect other options not supported, or new options needed (WASM_MEM_MAX)
- In particular MODULARIZE=1 does not work. We can work around this in qtloader.js.
Qt patches (historical)
We already have a (-no)-thread feature, and need to implement "threads enabled" mode.
https://codereview.qt-project.org/#/c/224400/ (removes MODULARIZE=1)
https://codereview.qt-project.org/#/c/224401/ (adds USE_PTHREADS=2)
Attachments
Issue Links
- is required for
-
QTBUG-72615 Porting Webassembly from a TP to fully supported
- Closed