Skip to content

Managing thread lifetimes off the main thread #18633

Open
@tlively

Description

@tlively

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions