Skip to content

Enable Wasm Workers to call pthread APIs in hybrid mode#26757

Merged
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:hybrid_thread_mode
Apr 23, 2026
Merged

Enable Wasm Workers to call pthread APIs in hybrid mode#26757
sbc100 merged 1 commit into
emscripten-core:mainfrom
sbc100:hybrid_thread_mode

Conversation

@sbc100
Copy link
Copy Markdown
Collaborator

@sbc100 sbc100 commented Apr 23, 2026

This change ends up adding ~200 bytes of data to each Wasm Worker (in
hybrid mode only) to store the struct pthread.

If the pthread_key_create API is used in the program then each worker
needs an additional 512 bytes to store the PTHREAD_KEYS_MAX (128)
pointers.

This change also essentially reverts the musl patch from #26673 since it
is no longer needed.

See #26631

Comment thread ChangeLog.md Outdated
Copy link
Copy Markdown
Collaborator

@juj juj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - was the design doc something that AI was able to work through?

@sbc100
Copy link
Copy Markdown
Collaborator Author

sbc100 commented Apr 23, 2026

Nice - was the design doc something that AI was able to work through?

I was hoping so.. but I actually took over and did this myself, since I have strong feeling about exactly how to do it.

For the first design doc docs/design/01-precise-futex-wakeups.md the AI was able to 95% of though!

@sbc100 sbc100 force-pushed the hybrid_thread_mode branch from 71028cb to fdea506 Compare April 23, 2026 17:28
This change ends up adding ~200 bytes of data to each Wasm Worker (in
hybrid mode only) to store the `struct pthread`.

If the `pthread_key_create` API is used in the program then each worker
needs an additional 512 bytes to store the PTHREAD_KEYS_MAX (128)
pointers.

This change also essentially reverts the musl patch from emscripten-core#26673 since it
is no longer needed.

See emscripten-core#26631
@sbc100 sbc100 force-pushed the hybrid_thread_mode branch from fdea506 to f1baad4 Compare April 23, 2026 17:33
@sbc100 sbc100 merged commit fd8ca23 into emscripten-core:main Apr 23, 2026
29 checks passed
@sbc100 sbc100 deleted the hybrid_thread_mode branch April 23, 2026 18:39
Comment thread site/source/docs/api_reference/wasm_workers.rst
sbc100 added a commit that referenced this pull request Apr 23, 2026
juj added a commit to juj/emscripten that referenced this pull request May 1, 2026
… longer feasible to run Wasm Workers with tiny stack sizes, after emscripten-core#26757 grew the used portion of the stack. Mass-convert all examples that use tiny 1KB Wasm Worker stack sizes to have a 4KB stacks. Fixes browser64.test_audioworklet_worker, which was failing due to emscripten_outf() overrunning the stack space over to atexit() data structure space. Add a runtime check to re-entrancy of exitRuntime() to detect nested re-entering back into exitRuntime() from within an atexit() handler. Closes emscripten-core#26823.
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.

3 participants