Repository navigation
Use Condition.timedWait in WakeUpFlag - #245
Merged
Merged
Conversation
sys.thread.Condition got a timed wait in HaxeFoundation/haxe#13109, so WakeUpFlag can block on a condition variable instead of a semaphore. This removes the invariant that exactly one permit exists while the state isn't Unset: clear() no longer has to take a permit that a racing setter may not have released yet, and requestWakeUp() becomes a single exchange instead of a CAS loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXGMZFfSGDAqgHttxSU
Both schedulers already loop around waitUntil, recomputing the due time after every return, so the wait itself doesn't need its own loop for spurious wake-ups and the remaining time. waitUntil now waits once and may return early, which replaces waitAndClear and tryWaitAndClear. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXGMZFfSGDAqgHttxSU
Simn
commented
Nov 6, 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.
HaxeFoundation/haxe#13109 added
Condition.timedWait, whichWakeUpFlagwas waiting for (its comment said so). This switches it from aSemaphoreto aCondition.That removes the invariant that exactly one semaphore permit exists while the state isn't
Unset:clear()is a plainexchange. It no longer has to take the permit of a racing setter, which could block until that setter released it.requestWakeUp()is a singleexchangeinstead of a CAS loop withBackOff.set()andrequestWakeUp()only take the mutex to signal when they move the state away fromUnset. The loop thread checks the state while holding the mutex, so it can't miss that change.waitUntilwaits once and may return early, on a spurious wake-up or a timeout the target cuts short. Both schedulers already loop around it: they clear the flag, look at their events and recompute the due time after every return. So the wait doesn't need its own loop for the remaining time. This replaceswaitAndClearandtryWaitAndClear, which onlywaitUntilused.This needs a Haxe nightly that includes HaxeFoundation/haxe@74c5b46, and on neko a runtime with condition variables. hxcoro master already needs a nightly neko for threads, because
lock_create(1)is missing from released neko too.Testing
Main tests and thread tests pass locally on eval, jvm, python and cpp, including the threadpool-dispatcher runs on eval, jvm and cpp. neko and hl weren't available locally, so CI covers them.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Va4FXGMZFfSGDAqgHttxSU