Skip to content

Can/should we make emscripten_futex_wait/wake API work in Wasm Workers. #26314

Closed

Description

@sbc100

Its doesn't seem like it should be hard to make them work.

It would help us fix things like #26283, and avoid issues like #26309 where folks might think the API was actually working.

Since #21618 it has been possible to call the API when both Wasm Workers and pthreads were enabled, but not when only Wasm Workers is used.

Activity

  1. sbc100 commented on Feb 20, 2026

    @sbc100
    CollaboratorAuthor

    I think as part of this we should also be able to make emscripten_is_main_runtime_thread work.

  2. sbc100 commented on Feb 20, 2026

    @sbc100
    CollaboratorAuthor
  3. sbc100 commented on Feb 23, 2026

    @sbc100
    CollaboratorAuthor

    Another thing we should perhaps do is not define pthread stub function at all when building with wasm workers.

    The pthread stub functions assume that they are being used in single threaded constext and should be used from wasm workers. Better to not define them at all maybe when wasm workers are enabled.

    What about then both wasm workers and pthreads are defined? Perhaps the pthread functions should assert in debug mode if they are ever called from a wasm worker?

  4. juj commented on Feb 24, 2026

    @juj
    Collaborator

    I'm all for making emscripten_futex_wait/wake API work in Wasm Workers, but I do feel strongly that it should be made in a way that does not creep the unconditional code size abstractions into the baseline overhead of Wasm Workers.

    Perhaps the pthread functions should assert in debug mode if they are ever called from a wasm worker?

    Agreed, after adding the combined pthread+wasm worker build mode, there is now this gap where if one does call many of the unsupported pthread functions from inside a wasm worker, issues will silently occur. A debug assert would be a great idea to help developers detect these issues.

    (before the combined pthread+wasm worker build mode, we would never link the pthread code, so that would deal with that issue automatically)

  5. sbc100 commented on Feb 24, 2026

    @sbc100
    CollaboratorAuthor

    (before the combined pthread+wasm worker build mode, we would never link the pthread code, so that would deal with that issue automatically)

    Is that true though? With pure wasm workers we link the stub versions of pthread API don't we? and they can silently succeed I think, because they assume the app they are linked into is single threaded.

  6. added a commit that references this issue on Feb 25, 2026
    dc80f64
  7. juj commented on Feb 25, 2026

    @juj
    Collaborator

    With pure wasm workers we link the stub versions of pthread API don't we?

    Ohh, I didn't recall that. I thought we'd not link in anything pthreads in Wasm Workers mode, so that it would result in a link error.

    Iideally we'd already croak at #include <pthread.h> to get compile time errors (unless we want to go down the route of partial pthread API impls on Wasm Workers), since that would explicitly make all the pthread stuff unavailable and ensure people aren't leaning on to the stubs. Though that would be a bit of include path wrangling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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