Repository navigation
Add timedWait to ConditionVariable - #1456
Merged
Merged
Conversation
Wait for at most the given number of seconds and return false if the timeout expired. Non-positive and NaN timeouts don't block, and very large ones are clamped so that the deadline does not overflow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu
Simn
pushed a commit
to HaxeFoundation/haxe
that referenced
this pull request
Nov 1, 2026
Use the new hxcpp `ConditionVariable::timedWait`, and install the hxcpp branch that adds it in CI until HaxeFoundation/hxcpp#1456 is merged. Add thread tests for timed waits: timing out with the mutex still held, being signaled, non-positive and NaN timeouts, and huge timeouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu
13 tasks done
Member
Author
|
@Aidan63 Could you check this? |
Simn
pushed a commit
to HaxeFoundation/haxe
that referenced
this pull request
Nov 5, 2026
HaxeFoundation/hxcpp#1456 has been merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu
Simn
added a commit
to HaxeFoundation/haxe
that referenced
this pull request
Nov 6, 2026
* Add optional timeout to sys.thread.Condition.wait Declare `wait(?timeout:Float):Bool` and document its semantics. The target implementations follow in later commits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [cpp] Implement Condition.wait with timeout, add tests Use the new hxcpp `ConditionVariable::timedWait`, and install the hxcpp branch that adds it in CI until HaxeFoundation/hxcpp#1456 is merged. Add thread tests for timed waits: timing out with the mutex still held, being signaled, non-positive and NaN timeouts, and huge timeouts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [hl] [neko] Implement Condition.wait with timeout hl uses the existing `condition_timed_wait` native and clamps the timeout itself, because older runtimes don't. CI builds the HashLink branch with the native fixes until HaxeFoundation/hashlink#1008 is merged. neko uses the new `cond_timed_wait` primitive when it is available (HaxeFoundation/neko#336), and otherwise polls with growing sleeps, using a counter that `signal` and `broadcast` increment to detect notifications. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [jvm] [python] [eval] Implement Condition.wait with timeout The build job's xmldoc step checks every target's std against the core API, so jvm and python must implement the new signature before CI can run any tests. - jvm: Condition.await with nanoseconds, like Semaphore.tryAcquire. - python: threading.Condition.wait, clamped to threading.TIMEOUT_MAX, above which Python raises an OverflowError. - eval: OCaml's Condition has no timed wait, so poll with growing sleeps like StdLock.wait and detect notifications with a counter that signal and broadcast increment. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [ci] Use the hxcpp branch with timedWait for docgen as well The docgen job builds dox for cpp, which includes sys.thread.Condition, and installs hxcpp separately from the cpp tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [jvm] Fix Condition.wait with huge timeouts Int64.fromFloat throws for values above 2^53, so a timeout above about 104 days threw while the mutex was held, and testTimedWaitHuge hung. Cap the wait at 9e6 seconds and report a capped wait that runs out as a spurious wakeup instead of a timeout. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [eval] Use libuv mutex and condition for Condition Replace the polling timed wait with Luv.Condition.timedwait, like Lock and Semaphore since #13110, which also removes the notification counter. libuv's mutex is recursive on Windows and aborts the process on misuse on POSIX, while OCaml's mutex raised Sys_error. Track the owning eval thread so that the mutex stays non-recursive on every platform and acquiring twice, or releasing or waiting without holding the mutex, throws a Haxe exception instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [ci] Build HashLink from its default branch again HaxeFoundation/hashlink#1008 has been merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [ci] Install hxcpp from its default branch again HaxeFoundation/hxcpp#1456 has been merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * [tests] Allow spurious wakeups in testTimedWaitTimesOut On Windows, MSVC's condition_variable_any::wait_for reports no_timeout when the OS wait returns slightly before the deadline, so a single wait(0.1) can return true. The API allows that as a spurious wakeup, so wait in a loop until a timeout is reported, like callers are expected to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * Split Condition.wait(?timeout) into wait() and timedWait(timeout) As discussed in review: wait() keeps its original signature and documentation, and the timed variant becomes timedWait(timeout):Bool, whose result always means something. This follows Semaphore, which has a blocking acquire():Void and a separate tryAcquire(?timeout):Bool. The target implementations are unchanged apart from the split. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu * Treat capped timedWait as spurious wakeup on all targets Relax the documentation: very large timeouts may be cut short at a target-specific limit, and such a wait returns true. Make python, cpp, hl and neko return true when the timeout exceeds their cap, as jvm and eval already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Va4FXDYWEo4mt53psuM5hu --------- Co-authored-by: Claude <noreply@anthropic.com>
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.
Adds
bool ConditionVariable_obj::timedWait(double seconds), the native side of the timedsys.thread.Condition.wait(?timeout:Float):Boolin HaxeFoundation/haxe#13109.std::condition_variable_any::wait_forinsidehx::AutoGCFreeZone, likewait(). It waits on the monotonic clock.falseif the timeout expired andtrueotherwise (signalled or a spurious wakeup). The mutex is held again on return in both cases.wait()is unchanged, so existing Haxe code that usesConditionkeeps working.Testing
g++ -std=c++17 -fsyntax-only).falseafter 0.1 s with the mutex held;0,-1andNaNreturnfalseat once; a1e12timeout returnstruewhen signalled after 0.1 s.tests/threads(TestCondition) on Add timed wait to sys.thread.Condition haxe#13109. That branch's CI will install this hxcpp branch until this is merged.Generated by Claude Code