Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allocate thread IDs for wasi_thread_spawn sequentially #7884

Merged
merged 1 commit into from
Feb 12, 2024

Conversation

Milek7
Copy link
Contributor

@Milek7 Milek7 commented Feb 7, 2024

TID returned by wasi_thread_spawn must be non-zero and upper three bits must always be zero: https://github.com/WebAssembly/wasi-threads?tab=readme-ov-file#design-choice-thread-ids

Current implementation didn't fulfill this requirements, only clearing the top bit from random value. This breaks wasi-libc mutexes when random TID is larger or equal to 0x3FFFFFFF.

Additionally, from birthday paradox probability of collision in allowed TID range nears 50% after spawning 27000 threads. This is large but not totally impossible, thus replace random generation with sequential allocation.

@Milek7 Milek7 requested a review from a team as a code owner February 7, 2024 13:52
@Milek7 Milek7 requested review from pchickey and removed request for a team February 7, 2024 13:52
@pchickey pchickey requested review from abrown and removed request for pchickey February 7, 2024 17:47
@abrown abrown added this pull request to the merge queue Feb 12, 2024
@abrown
Copy link
Collaborator

abrown commented Feb 12, 2024

@Milek7, thanks for the PR!

Merged via the queue into bytecodealliance:main with commit 9d487c5 Feb 12, 2024
19 checks passed
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