Skip to content

Fix emscripten_yield to avoid calling timers from Wasm Workers#26750

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:wasm_worker_yield
Apr 22, 2026
Merged

Fix emscripten_yield to avoid calling timers from Wasm Workers#26750
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:wasm_worker_yield

Conversation

@sbc100
Copy link
Copy Markdown
Collaborator

@sbc100 sbc100 commented Apr 22, 2026

Timers are only ever run on them main runtime thread. In #26655 I added an assertion to ensure that _emscripten_check_timers is only called from the main runtime thread. This broke tests such as lto0.test_wasm_worker_futex_wait.

The reason this test only failed in the LTO build on not under core0 is due to a bug in LTO which defeats the weak alias mechanism that is designed to only pull in the timer code when needed:

weak_alias(dummy, _emscripten_check_timers);

This changes fixes the stub version of emscripten_yield_stub so that it avoids calling _emscripten_check_timers from Wasm Workers.

Note: In a Wasm Workers build one can register and use timers from the main thread, but one cannot register a timer from a Wasm Worker (because _setitimer_js is a proxied func).

Fixes: #26749

@sbc100 sbc100 requested review from juj and kripken April 22, 2026 18:05
@juj
Copy link
Copy Markdown
Collaborator

juj commented Apr 22, 2026

Fantastic 👍

Timers are only ever run on them main runtime thread.  In emscripten-core#26655 I added
an assertion to ensure that `_emscripten_check_timers` is only called
from the main runtime thread.  This broke tests such as
`lto0.test_wasm_worker_futex_wait`.

The reason this test only failed in the LTO build on not under core0 is
due to a bug in LTO which defeats the weak alias mechanism that is
designed to only pull in the timer code when needed:

```
weak_alias(dummy, _emscripten_check_timers);
```

This changes fixes the stub version of `emscripten_yield_stub` so
that it avoids calling `_emscripten_check_timers` from Wasm Workers.

Note: In a Wasm Workers build one can register and use timers from the
main thread, but one cannot register a timer from a Wasm Worker (because
_setitimer_js is a proxied func).
@sbc100 sbc100 force-pushed the wasm_worker_yield branch from 6ec8049 to cbbf93c Compare April 22, 2026 20:05
@sbc100 sbc100 enabled auto-merge (squash) April 22, 2026 20:25
@sbc100 sbc100 disabled auto-merge April 22, 2026 20:25
@sbc100 sbc100 merged commit 16c0dba into emscripten-core:main Apr 22, 2026
17 of 29 checks passed
@sbc100 sbc100 deleted the wasm_worker_yield branch April 22, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lto0.test_wasm_worker_futex_wait failure

2 participants