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
Inline pthread worker.js file into the main output file (#21701)
This method has many advantages over the previous method of generating
a separate file:
- Avoids separate output file simplifying deployment.
- Avoids confusing laying of global scopes
- Avoids exporting symbols on the Module simply for visibility within
the worker file.
- Avoids code duplication
- Avoids the needs to importScripts call, and the node polyfill for
this.
- Allows optimizers such as closure and JSDCE to operate on the combined
code.
- `-sSINGLE_FILE` now works with pthreads
- Fewer network requests
- No need for locateFile logic to run on the worker to find the worker.js
The test_pthread_custom_pthread_main_url test was completely removed
since it was testing how worker.js was located and worker.js no longer
exists.
test_pthread_safe_stack depends on `onAbort` being proxied back to the
main thread. In this case the `onAbort` handler is injected
conditionally in `--pre-js=browser_report.js`. In the previous code
this meant that the proxied version took precedence because the pthread
handler override was injected first.
test_pthread_asan_use_after_free_2_wasmfs depends on `printErr` not
being proxied back to the main thread. It is injected unconditionally
during `--pre-js`. In the previous code path this means that
non-proxied version took precedence because it overrode the incoming
pthread handler.
Fixes: #9796
Copy file name to clipboardExpand all lines: site/source/docs/porting/pthreads.rst
-2Lines changed: 0 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -146,8 +146,6 @@ The Emscripten implementation for the pthreads API should follow the POSIX stand
146
146
147
147
- Pthreads + memory growth (``ALLOW_MEMORY_GROWTH``) is especially tricky, see `Wasm design issue #1271 <https://github.com/WebAssembly/design/issues/1271>`_. This currently causes JS accessing the Wasm memory to be slow - but this will likely only be noticeable if the JS does large amounts of memory reads and writes (Wasm runs at full speed, so moving work over can fix this). This also requires that your JS be aware that the HEAP* views may need to be updated - JS code embedded with ``--js-library`` etc will automatically be transformed to use the ``GROWABLE_HEAP_*`` helper functions where ``HEAP*`` are used, but external code that uses ``Module.HEAP*`` directly may encounter problems with views being smaller than memory.
148
148
149
-
Also note that when compiling code that uses pthreads, an additional JavaScript file ``NAME.worker.js`` is generated alongside the output .js file (where ``NAME`` is the basename of the main file being emitted). That file must be deployed with the rest of the generated code files. By default, ``NAME.worker.js`` will be loaded relative to the main HTML page URL. If it is desirable to load the file from a different location e.g. in a CDN environment, then one can define the ``Module.locateFile(filename)`` function in the main HTML ``Module`` object to return the URL of the target location of the ``NAME.worker.js`` entry point. If this function is not defined in ``Module``, then the default location relative to the main HTML file is used.
Copy file name to clipboardExpand all lines: src/postamble_minimal.js
+24-9Lines changed: 24 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -89,15 +89,6 @@ function initRuntime(wasmExports) {
89
89
90
90
// Initialize wasm (asynchronous)
91
91
92
-
varimports={
93
-
#if MINIFY_WASM_IMPORTED_MODULES
94
-
'a': wasmImports,
95
-
#else // MINIFY_WASM_IMPORTED_MODULES
96
-
'env': wasmImports,
97
-
'{{{ WASI_MODULE_NAME }}}': wasmImports,
98
-
#endif // MINIFY_WASM_IMPORTED_MODULES
99
-
};
100
-
101
92
// In non-fastcomp non-asm.js builds, grab wasm exports to outer scope
102
93
// for emscripten_get_exported_function() to be able to access them.
103
94
#if LibraryManager.has('library_exports.js')
@@ -112,6 +103,20 @@ var wasmModule;
112
103
<<<WASM_MODULE_EXPORTS_DECLARES>>>
113
104
#endif
114
105
106
+
#if PTHREADS
107
+
functionloadModule(){
108
+
assignWasmImports();
109
+
#endif
110
+
111
+
varimports={
112
+
#if MINIFY_WASM_IMPORTED_MODULES
113
+
'a': wasmImports,
114
+
#else // MINIFY_WASM_IMPORTED_MODULES
115
+
'env': wasmImports,
116
+
'{{{ WASI_MODULE_NAME }}}': wasmImports,
117
+
#endif // MINIFY_WASM_IMPORTED_MODULES
118
+
};
119
+
115
120
#if MINIMAL_RUNTIME_STREAMING_WASM_INSTANTIATION
116
121
// https://caniuse.com/#feat=wasm and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming
117
122
// Firefox 52 added Wasm support, but only Firefox 58 added instantiateStreaming.
0 commit comments