emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.82k stars 3.31k forks source link

Impossible to run multithread functions without blocking the UI thread. #22098

Open qdwang opened 5 months ago

qdwang commented 5 months ago

Please include the following in your bug report:

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.57-git
clang version 19.0.0git
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.57/libexec/llvm/bin

Failing command line in full: No failing command.

Full link command and output with -v appended: -pthread -sPTHREAD_POOL_SIZE=navigator.hardwareConcurrency -O3 -flto -sENVIRONMENT="web, worker" -sFILESYSTEM=0 -sALLOW_MEMORY_GROWTH -sEXPORT_NAME=libxxx -sMODULARIZE


This will generate three files: libxxx.js, libxxx.wasm, libxxx.worker.js. If I directly use libxxx.js in <script src="libxxx.js"></script>, the C function works but it will block the UI thread. If I try to import libxxx.js by using importScripts("libtinydng.js"); in a custom worker file, it won't work also.

qdwang commented 5 months ago

setting mainScriptUrlOrBlob to the url of libxxx.js can solve this issue

sbc100 commented 4 months ago

You should not need to set mainScriptUrlOrBlob just to make this work.

Can I ask you, were you setting mainScriptUrlOrBlob to something else prior to this fix?