Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64625

webassembly: pthreads support

    XMLWordPrintable

Details

    • Task
    • Resolution: Done
    • P2: Important
    • 5.13.0
    • None
    • QPA
    • 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:

      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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              sorvig Morten Sørvig
              lpotter Lorn Potter
              Votes:
              3 Vote for this issue
              Watchers:
              13 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes