emscripten-core / emscripten-core/emscripten

Managing thread lifetimes off the main thread

Open
#18,633 0 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

It would be really great if we could get the main browser thread out of the business of managing thread lifetimes, especially for spawning new threads. The fact that the main thread currently has to return to the event loop before a new thread can become active means that APIs that synchronously start new worker threads (like creating the WasmFS OPFS backend) cannot be called from the main thread without deadlocking. Even without deadlocks, depending on the main thread can be a performance problem when the main thread is busy.

Unfortunately, we can't move thread management off the main thread because stable Safari does not yet support spawning workers from other workers (although Safari Technical Preview does).

We can track Safari's support status here: https://wpt.fyi/results/workers/nested_worker.worker.html?label=master&label=stable&aligned&view=subtest

Once stable Safari has supported nested workers for a while, we should move thread management to a worker (probably the messageRelay worker) that does not run user code. To avoid having to maintain and test two code paths for worker management, we will have to drop support for older Safari + pthreads at that point, so we'll probably want to check in on emscripten-discuss first.

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.