Remove loop from emscripten_thread_sleep. NFC#26585
Merged
sbc100 merged 1 commit intoemscripten-core:mainfrom Apr 3, 2026
Merged
Remove loop from emscripten_thread_sleep. NFC#26585sbc100 merged 1 commit intoemscripten-core:mainfrom
sbc100 merged 1 commit intoemscripten-core:mainfrom
Conversation
86bb623 to
47ee417
Compare
We have code in the lower level emscrpeten_futex_wait that take care of splitting up the wait for the main runtime thread. For normal pthreads I don't see any need to run the message queue while the thread is sleeping like this. Instead, it can run from the event loop, or explicitly run. Followup to emscripten-core#26471
47ee417 to
6911619
Compare
tlively
reviewed
Apr 1, 2026
Member
There was a problem hiding this comment.
What is the intent of the changes in this file?
Collaborator
Author
There was a problem hiding this comment.
See the final paragraph on the PR description. Basically: To make the total time slept for within this function more accurate.
Collaborator
Author
There was a problem hiding this comment.
Maybe I'll split that part of the change out actually..
Collaborator
Author
There was a problem hiding this comment.
Actually I think this makes sense to keep as part of this PR.
Basically I've removing the outer loops which means the inner loops now needs to be more accruate. I'll add more to the PR description.
dschuff
reviewed
Apr 1, 2026
tlively
approved these changes
Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have code in the lower level
emscrpeten_futex_waitthat takes care of splitting up the wait for the main runtime thread.For normal pthreads I don't see any need to run the message queue constantly while the thread is sleeping.
As part of this change I found that I had to improve the accuracy of the timeslicing
emscripten_futex_wait.The new code uses an absolute target time, so regardless of how much time it spends between calls to
atomic.waitit still returns at the correct time.Previously we were assuming that we could call
atomic.wait32with 1ms timeout N times to achieve Nms of sleeping, but this doesn't always hold, for various reasons.Followup to #26471