emscripten-core / emscripten-core/emscripten

Pausing all threads

Open
#16,676 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 6h
Merged PRs (30d)
109

Description

**Version of emscripten/emsdk:**
3.1.5

It seems that there is currently no option to pause my wasm app (ffmpeg). When executing, it spins up ~20 pthreads/workers. I would like to have an option to pause the whole thing, but with my current approach it keeps running (and sending logs via callback).

My build configuration:

```
-s EXPORTED_FUNCTIONS="[..., _emscripten_pause_main_loop, _emscripten_resume_main_loop, _emscripten_sleep]"
-s DEFAULT_LIBRARY_FUNCS_TO_INCLUDE="[emscripten_pause_main_loop, emscripten_resume_main_loop, emscripten_sleep]"
-s ASYNCIFY
-s USE_PTHREADS=1
-s PROXY_TO_PTHREAD=1
-s ENVIRONMENT=worker
-pthread
...
```

What I tried:

my-worker.js:

```js
module.pauseMainLoop(); // seems the same as module._emscripten_pause_main_loop
for(const pthread of Object.values(module.PThread.pthreads))
pthread.worker.postMessage({cmd:"pause"});
```

customized generated ffmpeg.worker.js:

```js
else if(e.data.cmd==="pause")
Module.pauseMainLoop();
```

I have also tried `module._emscripten_sleep(...)` but same result.

Is there any other approach to take preferably on javascript side, without doing heavy modifications in native code?

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.