Update emscripten_futex_wait to return -EINTR on spurious wakeups. NFC#26735
Merged
Conversation
ede491d to
d251166
Compare
sbc100
commented
Apr 21, 2026
| } | ||
|
|
||
| unsupported = { | ||
| 'test_pthread_spin_lock_1_1': 'alarm causes spurious wakeup during pthread_join', |
Collaborator
Author
There was a problem hiding this comment.
I should have realized this was not the correct behavior when I made this change.
emscripten_futex_wait to return -EINTR on spurious wakeups. NFC
kripken
reviewed
Apr 21, 2026
| // Returns -ETIMEOUT if the maxWaitMilliseconds timeout was exceeded. | ||
| // Returns -EINTR if the operation was interrupted (e.g. a timer fired, or an | ||
| // async signal was received). | ||
| // Returns 0 on success (i.e. Another thread signaled this address) |
Member
There was a problem hiding this comment.
Suggested change
| // Returns 0 on success (i.e. Another thread signaled this address) | |
| // Returns 0 on success (i.e. another thread signaled this address) |
| // __builtin_wasm_memory_atomic_wait32 so we have busy wait instead. | ||
| if (!_emscripten_thread_supports_atomics_wait()) { | ||
| ret = futex_wait_main_browser_thread(addr, val, max_wait_ms, cancelable); | ||
| emscripten_conditional_set_current_thread_status(EM_THREAD_STATUS_WAITFUTEX, EM_THREAD_STATUS_RUNNING); |
Collaborator
Author
There was a problem hiding this comment.
The emscripten_conditional_set_current_thread_status pushing and popping is now handled by the wrapper function below. It allows simpler control flow in this function since no all exit paths need to remember to do this anymore (also removes some duplication).
96204a4 to
22298f0
Compare
The internal musl code assumes that futex wait return -EINTR if the wait is interrupted. We return -EINTR here in case we wakeup to run a timer or if were notified to wake up by another thread using `emscripten_thread_notify`.
kripken
approved these changes
Apr 22, 2026
Member
kripken
left a comment
There was a problem hiding this comment.
I'm not an expert on this but it looks right.
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.
The internal musl code assumes that futex wait returns -EINTR if the wait is interrupted.
We return -EINTR here in case we wakeup to run a timer or if were notified to wake up by another thread using
emscripten_thread_notify.Followup to #26659