emscripten-core / emscripten-core/emscripten

Impossible to run multithread functions without blocking the UI thread.

Open
#22,098 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

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 ``, 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.
- With `-sEXPORT_NAME=libxxx -sMODULARIZE`, it will cause an error on the `libxxx.worker.js`: `Uncaught TypeError: Failed to execute 'createObjectURL' on 'URL': Overload resolution failed.`
- Without `-sEXPORT_NAME=libxxx -sMODULARIZE`, the custom worker file will be loaded multiple times and multithreading just stop working.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.