Skip to content

Add timedWait to ConditionVariable for Haxe 5's Condition - #441

Merged
dimensionscape merged 1 commit into
mainfrom
fix/condition-timed-wait
Nov 13, 2026
Merged

dimensionscape merged 1 commit into
mainfrom
fix/condition-timed-wait

Conversation

@dimensionscape

Copy link
Copy Markdown
Member

The Haxe nightly's sys.thread.Condition now has timedWait, which calls hx::thread::ConditionVariable's. libhxcpp had none, so every program that used Condition failed to compile with the nightly ('struct hx::thread::ConditionVariable_obj' has no member named 'timedWait'), and most jobs of the nightly workflow failed on it, regression and gc stress builds included.

timedWait(seconds) returns true once a signal or broadcast came during the wait and false when the time ran out.

  • NaN, zero and a negative time don't wait. The wait is capped at 1e9 seconds, which keeps the deadline inside the clock's range, and the Haxe side counts a capped wait that ran out as a spurious wakeup.
  • MSVC's timed waits return no_timeout about half a millisecond before the deadline with nothing signalled. Here that happened in 17 of 30 runs of a 50 ms wait. So a wakeup counts only when the count of signals and broadcasts moved, and a wakeup without one waits again until the deadline.

ConditionTimedWait checks a wait that runs out, the waits that don't wait, a signal from another thread, and a wait past the cap. It calls the runtime from native code, so it builds with every Haxe. Here it matches 40 of 40 runs with Haxe 4.3.7 and passes with the Haxe nightly (5.0.0-preview.1+3cfeac4). A program using the nightly's own Condition.timedWait builds and runs, and so does CppiaTimeStampMs, which failed to build in the nightly run.

This is Haxe 5 work, so per CONTRIBUTING it isn't a release blocker. It brings the nightly workflow back to testing the API level 500 code.

The Haxe nightly's sys.thread.Condition has timedWait, which calls
hx::thread::ConditionVariable's, and libhxcpp had none, so every program
that used Condition failed to compile and most of the nightly workflow's
jobs failed.

timedWait returns true once a signal or broadcast came during the wait
and false when the time ran out. NaN, zero and a negative time do not
wait, and the wait is capped at 1e9 seconds, which keeps the deadline
inside the clock's range, as the Haxe side expects. MSVC's timed waits
return no_timeout about half a millisecond before the deadline with
nothing signalled, about half the time for a 50 ms wait, so a wakeup
counts only when the count of signals moved, and one without waits again.

ConditionTimedWait checks a wait that runs out, waits that do not wait, a
signal from another thread, and a wait past the cap, with native calls
that build with every Haxe.
@dimensionscape
dimensionscape merged commit d8f9651 into main Nov 13, 2026
37 checks passed
@dimensionscape
dimensionscape deleted the fix/condition-timed-wait branch November 13, 2026 08:21
@dimensionscape dimensionscape mentioned this pull request Nov 13, 2026
28 of 34 tasks
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.

1 participant