emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.36k stars 3.25k forks source link

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

Open qdwang opened 2 weeks ago

qdwang commented 2 weeks 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 2 weeks ago

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

sbc100 commented 2 weeks 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?