Skip to content

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

Open
sbc100 wants to merge 2 commits intoemscripten-core:mainfrom
sbc100:hybrid_thread_mode
Open

Enable Wasm Workers to call pthread APIs in hybrid mode#26757
sbc100 wants to merge 2 commits intoemscripten-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

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 787860e to 71028cb Compare April 23, 2026 06:24
Comment thread ChangeLog.md
as locks and condvars will now fail with ENOTSUP. (#26743)
- When building code with bith Wasm Workers and pthreads (hybrid mode) it is now
possible to call most of the core pthread APIs (e.g. lock, condvar, etc) from
a Wasm Worker. This mode increase the memroy used by each Wasm Worker by
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(not critical, though noticed bith, increase->increases, memroy)

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!

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.

2 participants