Skip to content

Use Condition.timedWait in WakeUpFlag - #245

Merged
Simn merged 2 commits into
masterfrom
claude/friendly-darwin-nzycwd
Nov 6, 2026
Merged

Simn merged 2 commits into
masterfrom
claude/friendly-darwin-nzycwd

Conversation

@Simn

@Simn Simn commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

HaxeFoundation/haxe#13109 added Condition.timedWait, which WakeUpFlag was waiting for (its comment said so). This switches it from a Semaphore to a Condition.

That removes the invariant that exactly one semaphore permit exists while the state isn't Unset:

  • clear() is a plain exchange. It no longer has to take the permit of a racing setter, which could block until that setter released it.
  • requestWakeUp() is a single exchange instead of a CAS loop with BackOff.
  • set() and requestWakeUp() only take the mutex to signal when they move the state away from Unset. The loop thread checks the state while holding the mutex, so it can't miss that change.
  • waitUntil waits 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 replaces waitAndClear and tryWaitAndClear, which only waitUntil used.

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

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
Comment thread src/hxcoro/schedulers/WakeUpFlag.hx Resolved
@Simn
Simn merged commit 79af61d into master Nov 6, 2026
30 checks passed
@Simn
Simn deleted the claude/friendly-darwin-nzycwd branch November 6, 2026 22:50
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.

2 participants