GPU: two frame waits that wake together take two ticks #357

Closed
github-bot wants to merge 2 commits from gh-pr/357/head into gh-pr/357/base
Owner

@⁠JordanFableFur on GitHub · 2026-11-24 23:50 UTC · original
JordanFableFur:fix/frame-flip-tick-race → main · +48 −7 · 1 files · 2 commits · closed without merging

What

Two waits for one event kind could both end on the same tick: each computed the next tick, slept, and raised last with fetch_max without looking at what it returned, so both reported S_OK on one tick — an event happening once per tick handed two waiters the same one.

A wait now claims its tick through fetch_max's previous value. One that lost the race waits again on the next tick, with what it has already slept taken off its time-out, so the caller's deadline does not stretch and the retry does not extend it.

Fixes #244.

Testing

A regression starts two flip waits together and asserts both return S_OK and that the next tick after the run is the one after both (each took its own tick). The existing single-waiter test is unchanged and passes.

Validated on Windows CI (fork-run of the repository workflow): clippy both builds and the full test suite pass: https://github.com/JordanFableFur/victory-fork/actions/runs/45513129011

AI use: written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.

**@⁠JordanFableFur** on GitHub · 2026-11-24 23:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/357) `JordanFableFur:fix/frame-flip-tick-race` → `main` · +48 −7 · 1 files · 2 commits · closed without merging ## What Two waits for one event kind could both end on the same tick: each computed the next tick, slept, and raised `last` with `fetch_max` without looking at what it returned, so both reported `S_OK` on one tick — an event happening once per tick handed two waiters the same one. A wait now claims its tick through `fetch_max`'s previous value. One that lost the race waits again on the next tick, with what it has already slept taken off its time-out, so the caller's deadline does not stretch and the retry does not extend it. Fixes #244. ## Testing A regression starts two flip waits together and asserts both return `S_OK` and that the next tick after the run is the one after both (each took its own tick). The existing single-waiter test is unchanged and passes. Validated on Windows CI (fork-run of the repository workflow): clippy both builds and the full test suite pass: https://github.com/JordanFableFur/victory-fork/actions/runs/45513129011 **AI use:** written with Codex and Claude Code (GPT-5.2 Codex); reviewed and posted with my approval. No game files were used.
Two waits for one event could both end on the same tick: each computed
the next tick, slept, and raised loki       ttys005                         Tue Nov 24 16:03   still logged in
loki       ttys004                         Sun Nov 22 09:50   still logged in
loki       ttys004                         Thu Nov 19 14:40 - 14:40  (00:00)
loki       ttys005                         Wed Nov 18 22:14 - 22:14  (00:00)
loki       ttys004                         Wed Nov 18 22:13 - 22:13  (00:00)
loki       ttys003                         Wed Nov 18 21:47   still logged in
loki       ttys003                         Tue Nov 17 18:48 - 18:48  (00:00)
loki       ttys004  100.96.19.73           Tue Nov 17 16:18 - 16:19  (00:01)
loki       ttys004  100.96.19.73           Tue Nov 17 16:18 - 16:18  (00:00)
loki       ttys004  100.96.19.73           Tue Nov 17 16:15 - 16:15  (00:00)
loki       ttys003                         Tue Nov 17 16:15 - 16:15  (00:00)
loki       ttys002                         Thu Nov 12 09:01   still logged in
loki       ttys002                         Tue Nov 10 14:10 - 14:10  (00:00)
loki       ttys002                         Tue Nov 10 14:03 - 14:03  (00:00)
loki       ttys001                         Tue Nov 10 09:58   still logged in
loki       ttys000                         Mon Nov  9 21:50   still logged in
loki       ttys001                         Mon Nov  9 21:48 - 21:48  (00:00)
loki       ttys006                         Sat Nov  7 13:26 - 13:26  (00:00)
loki       ttys006                         Sat Nov  7 11:55 - 11:55  (00:00)
loki       ttys005                         Sat Nov  7 11:55 - 11:55  (00:00)
loki       ttys001                         Sat Nov  7 11:44 - 11:44  (00:00)
loki       ttys004                         Thu Nov  5 00:51 - 00:51  (00:00)
loki       ttys002                         Wed Nov  4 23:22 - 23:22  (00:00)
loki       ttys001                         Wed Nov  4 11:33 - 11:33  (00:00)
loki       ttys001                         Wed Nov  4 10:54 - 10:54  (00:00)
loki       ttys001                         Wed Nov  4 10:08 - 10:08  (00:00)
loki       ttys002                         Mon Nov  2 15:41 - 15:41  (00:00)
loki       ttys001                         Sun Nov  1 12:15 - 12:15  (00:00)
loki       ttys001                         Fri Oct 30 10:07 - 10:07  (00:00)
loki       ttys001                         Thu Oct 29 11:53 - 11:53  (00:00)
loki       ttys003                         Mon Oct 26 14:45 - 14:45  (00:00)
loki       ttys001                         Sun Oct 25 12:39 - 12:39  (00:00)
loki       ttys006                         Tue Oct 20 16:32 - 16:32  (00:00)
loki       ttys005                         Mon Oct 19 14:10 - 14:10  (00:00)
loki       ttys003                         Mon Oct 19 13:16 - 13:16  (00:00)
loki       ttys006                         Sun Oct 18 16:45 - 16:45  (00:00)
loki       ttys005                         Sun Oct 18 16:37 - 16:37  (00:00)
loki       ttys004                         Sun Oct 18 16:37 - 16:37  (00:00)
loki       ttys003                         Sun Oct 18 16:37 - 16:37  (00:00)
loki       ttys002                         Sun Oct 18 16:37 - 16:37  (00:00)
loki       ttys001                         Sun Oct 18 16:37 - 16:37  (00:00)
loki       ttys000                         Sun Oct 18 16:37 - 16:37  (00:00)
loki       console                         Sun Oct 18 16:37   still logged in
reboot time                                Sun Oct 18 16:37
shutdown time                              Sun Oct 18 16:37
loki       ttys006                         Sun Oct 18 16:30 - 16:30  (00:00)
loki       ttys005                         Sun Oct 18 16:27 - 16:27  (00:00)
loki       ttys004                         Sun Oct 18 16:15 - 16:15  (00:00)
loki       ttys003                         Sun Oct 18 16:15 - 16:15  (00:00)
loki       ttys002                         Sun Oct 18 16:15 - 16:15  (00:00)
loki       ttys001                         Sun Oct 18 16:15 - 16:15  (00:00)
loki       ttys000                         Sun Oct 18 16:15 - 16:15  (00:00)
loki       console                         Sun Oct 18 16:15 - 16:37  (00:21)
reboot time                                Sun Oct 18 16:01
shutdown time                              Sun Oct 18 15:34
loki       ttys004                         Sat Oct 17 00:37 - 00:37  (00:00)
loki       ttys003                         Fri Oct 16 22:41 - 22:41  (00:00)
loki       ttys003                         Fri Oct 16 22:38 - 22:38  (00:00)
loki       ttys003                         Fri Oct 16 13:58 - 13:58  (00:00)
loki       ttys005                         Fri Oct 16 01:14 - 01:14  (00:00)
loki       ttys004                         Thu Oct 15 19:56 - 19:56  (00:00)
loki       ttys004                         Thu Oct 15 19:56 - 19:56  (00:00)
loki       ttys002                         Mon Oct 12 15:05 - 15:05  (00:00)
loki       ttys001                         Sun Oct 11 16:13 - 16:13  (00:00)
loki       ttys002                         Sun Oct 11 16:12 - 16:12  (00:00)
loki       ttys001                         Sun Oct 11 15:31 - 15:31  (00:00)
loki       ttys003                         Tue Oct  6 23:14 - 23:14  (00:00)
loki       ttys002                         Sat Oct  3 12:54 - 12:54  (00:00)
loki       ttys001                         Sat Oct  3 12:50 - 12:50  (00:00)
loki       ttys006                         Fri Oct  2 12:12 - 12:12  (00:00)
loki       ttys005                         Thu Oct  1 15:52 - 15:52  (00:00)
loki       ttys005                         Thu Oct  1 01:16 - 01:16  (00:00)
loki       ttys004                         Wed Sep 30 19:57 - 19:57  (00:00)
loki       ttys004                         Wed Sep 30 13:37 - 13:37  (00:00)
loki       ttys004                         Wed Sep 30 09:03 - 09:03  (00:00)
loki       ttys003                         Wed Sep 30 09:03 - 09:03  (00:00)
loki       ttys003                         Tue Sep 29 20:42 - 20:42  (00:00)
loki       ttys002                         Tue Sep 29 20:42 - 20:42  (00:00)
loki       ttys003                         Tue Sep 29 20:31 - 20:31  (00:00)
loki       ttys003                         Tue Sep 29 20:29 - 20:29  (00:00)
loki       ttys005                         Tue Sep 29 18:03 - 18:03  (00:00)
loki       ttys005                         Tue Sep 29 18:03 - 18:03  (00:00)
loki       ttys005                         Tue Sep 29 16:55 - 16:55  (00:00)
loki       ttys004                         Tue Sep 29 16:55 - 16:55  (00:00)
loki       ttys003                         Tue Sep 29 16:33 - 16:33  (00:00)
loki       ttys002                         Tue Sep 29 16:19 - 16:19  (00:00)
loki       ttys001                         Tue Sep 29 16:19 - 16:19  (00:00)
loki       ttys001                         Tue Sep 29 16:18 - 16:18  (00:00)
loki       ttys001                         Tue Sep 29 16:18 - 16:18  (00:00)
loki       ttys002                         Tue Sep 29 16:15 - 16:15  (00:00)
loki       ttys001                         Tue Sep 29 16:06 - 16:06  (00:00)
loki       ttys002                         Tue Sep 29 15:51 - 15:51  (00:00)
loki       ttys002                         Tue Sep 29 15:51 - 15:51  (00:00)
loki       ttys002                         Tue Sep 29 15:50 - 15:50  (00:00)
loki       ttys002                         Tue Sep 29 15:49 - 15:49  (00:00)
loki       ttys002                         Tue Sep 29 15:49 - 15:49  (00:00)
loki       ttys001                         Tue Sep 29 15:48 - 15:48  (00:00)
loki       ttys000                         Tue Sep 29 15:32 - 15:32  (00:00)
loki       ttys001                         Tue Sep 29 15:29 - 15:29  (00:00)
loki       ttys000                         Tue Sep 29 15:28 - 15:28  (00:00)
loki       console                         Tue Sep 29 15:10 - 15:34 (19+00:23)
_mbsetupuser console                         Tue Sep 29 15:09 - 15:10  (00:01)
root       console                         Tue Sep 29 15:09 - 15:09  (00:00)
reboot time                                Tue Sep 29 15:08
root       console                         Tue Sep 29 15:06 - crash  (00:01)
_mbsetupuser console                         Tue Sep 29 14:59 - 15:06  (00:06)
root       console                         Tue Sep 29 14:59 - 14:59  (00:00)
reboot time                                Tue Sep 29 14:52
reboot time                                Fri Sep 18 11:36
reboot time                                Fri Sep 18 11:31

wtmp begins Fri Sep 18 11:31:12 MST 2026 with fetch_max without looking
at what it returned, so both reported success on one tick.

A wait now claims its tick with fetch_max's previous value. One that
lost the tick waits again on the next one, against the time-out it was
given (what it has already slept comes off it), so two concurrent waits
report two ticks and the caller's deadline does not stretch.

A regression starts two flip waits together and asserts both end on
their own tick.

AI use: written with Codex and Claude Code (GPT-5.2 Codex); reviewed and
posted with my approval. No game files were used.
Review of the first fix: the retry took the next tick with fetch_max
without its previous value, so two retries could still share a tick,
the time left came off the first sleep's request rather than the clock
(a wake that ran late stretched the caller's time-out), and the
diagnostics only counted the first sleep.

The wait now loops: sleep, claim (fetch_max's previous value decides),
and a loser recomputes the next tick; the time-out is measured from the
call, the retry sleeps count into the pacing diagnostics, and the
concurrent-waits regression asserts the last tick moved two on.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:41:33 +00:00
github-bot closed this pull request 2026-11-26 03:41:33 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:50 UTC · original · edited 2026-11-24 23:55 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:55:39.336990Z 267a784 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#issuecomment-7147859190) · edited 2026-11-24 23:55 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"267a784b0e15a92104b62f40b1cac87faaa37b4d","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T23:55:39.336990Z">2026-11-24T23:55:39.336990Z</relative-time> | `267a784` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠JordanFableFur on GitHub · 2026-11-25 00:32 UTC · original

All four findings addressed in f005ddd:

  • The claim is in a loop: a loser recomputes the next tick and claims again, checking fetch_max's previous value each time, so three synchronized waiters take three ticks.
  • The deadline is measured from the call (limit.saturating_sub(slept) per attempt), so a late wake does not stretch the caller's time-out.
  • The retry sleeps count into C::PaceUs (slept.min(limit)).
  • The regression asserts LAST moved exactly two on across two barrier-synchronized waits, which the pre-change code fails.
**@⁠JordanFableFur** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#issuecomment-7148622946) All four findings addressed in f005ddd: - The claim is in a loop: a loser recomputes the next tick and claims again, checking `fetch_max`'s previous value each time, so three synchronized waiters take three ticks. - The deadline is measured from the call (`limit.saturating_sub(slept)` per attempt), so a late wake does not stretch the caller's time-out. - The retry sleeps count into `C::PaceUs` (`slept.min(limit)`). - The regression asserts `LAST` moved exactly two on across two barrier-synchronized waits, which the pre-change code fails.
Author
Owner

@⁠kaayzouee on GitHub · 2026-11-25 01:17 UTC · original

Duplicate of #281?

**@⁠kaayzouee** on GitHub · 2026-11-25 01:17 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#issuecomment-7149404574) Duplicate of #281?
Author
Owner

@⁠JordanFableFur on GitHub · 2026-11-25 01:46 UTC · original

Closing — #281 fixes the same issue (#244) and was opened first, with the same claim-and-retry shape. Thanks for flagging.

**@⁠JordanFableFur** on GitHub · 2026-11-25 01:46 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#issuecomment-7149937107) Closing — #281 fixes the same issue (#244) and was opened first, with the same claim-and-retry shape. Thanks for flagging.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:55 UTC · original
On crates/victory-gpu/src/frame.rs line 165 (outdated):

@@ -147,8 +147,26 @@ pub(crate) extern "system" fn wait(
         TIMEOUT
     } else {
         std::thread::sleep(wait);
-        last(kind).fetch_max(tick, Ordering::Relaxed);
-        S_OK
+        // The tick is this waiter's only when it advanced `last`: two waits
+        // that wake together otherwise both end on it. A loser waits again,
+        // on the next tick, against its original time-out.
+        let claimed = last(kind).fetch_max(tick, Ordering::Relaxed) < tick;
+        if claimed {
+            S_OK
+        } else if limit > wait {
+            let left = limit - wait;
+            let (tick, wait) = next_tick(kind);
+            if wait > left {
+                std::thread::sleep(left);
+                TIMEOUT
+            } else {
+                std::thread::sleep(wait);
+                last(kind).fetch_max(tick, Ordering::Relaxed);
+                S_OK

P2 Badge Recheck tick ownership after every retry

With three waits for the same kind targeting tick N, the two initial losers both retry tick N+1. This second fetch_max ignores its previous value, so both retries return S_OK even though only one claims that tick; a synchronized three-waiter probe produced three successes while LAST advanced by only two ticks. This can also occur with two threads if the first winner starts another wait. Keep the ownership check in a retry loop until a tick is actually claimed or the deadline expires.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:55 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#discussion_r4688247850) On `crates/victory-gpu/src/frame.rs` line 165 (outdated): ```diff @@ -147,8 +147,26 @@ pub(crate) extern "system" fn wait( TIMEOUT } else { std::thread::sleep(wait); - last(kind).fetch_max(tick, Ordering::Relaxed); - S_OK + // The tick is this waiter's only when it advanced `last`: two waits + // that wake together otherwise both end on it. A loser waits again, + // on the next tick, against its original time-out. + let claimed = last(kind).fetch_max(tick, Ordering::Relaxed) < tick; + if claimed { + S_OK + } else if limit > wait { + let left = limit - wait; + let (tick, wait) = next_tick(kind); + if wait > left { + std::thread::sleep(left); + TIMEOUT + } else { + std::thread::sleep(wait); + last(kind).fetch_max(tick, Ordering::Relaxed); + S_OK ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Recheck tick ownership after every retry** With three waits for the same kind targeting tick N, the two initial losers both retry tick N+1. This second `fetch_max` ignores its previous value, so both retries return `S_OK` even though only one claims that tick; a synchronized three-waiter probe produced three successes while `LAST` advanced by only two ticks. This can also occur with two threads if the first winner starts another wait. Keep the ownership check in a retry loop until a tick is actually claimed or the deadline expires. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:55 UTC · original
On crates/victory-gpu/src/frame.rs line 157 (outdated):

@@ -147,8 +147,26 @@ pub(crate) extern "system" fn wait(
         TIMEOUT
     } else {
         std::thread::sleep(wait);
-        last(kind).fetch_max(tick, Ordering::Relaxed);
-        S_OK
+        // The tick is this waiter's only when it advanced `last`: two waits
+        // that wake together otherwise both end on it. A loser waits again,
+        // on the next tick, against its original time-out.
+        let claimed = last(kind).fetch_max(tick, Ordering::Relaxed) < tick;
+        if claimed {
+            S_OK
+        } else if limit > wait {
+            let left = limit - wait;

P2 Badge Calculate the retry budget from elapsed time

When the initial sleep wakes late, subtracting its requested duration leaves more retry time than the caller actually has. For example, with a 30 ms timeout, a requested 20 ms sleep that wakes at 25 ms leaves only 5 ms, but this calculation allows another 10 ms sleep and returns TIMEOUT at 35 ms. A controlled timing probe reproduces that overrun without any oversleep on the retry itself. Use an absolute deadline and recompute the remaining duration from elapsed time before sleeping again.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:55 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#discussion_r4688247856) On `crates/victory-gpu/src/frame.rs` line 157 (outdated): ```diff @@ -147,8 +147,26 @@ pub(crate) extern "system" fn wait( TIMEOUT } else { std::thread::sleep(wait); - last(kind).fetch_max(tick, Ordering::Relaxed); - S_OK + // The tick is this waiter's only when it advanced `last`: two waits + // that wake together otherwise both end on it. A loser waits again, + // on the next tick, against its original time-out. + let claimed = last(kind).fetch_max(tick, Ordering::Relaxed) < tick; + if claimed { + S_OK + } else if limit > wait { + let left = limit - wait; ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Calculate the retry budget from elapsed time** When the initial sleep wakes late, subtracting its requested duration leaves more retry time than the caller actually has. For example, with a 30 ms timeout, a requested 20 ms sleep that wakes at 25 ms leaves only 5 ms, but this calculation allows another 10 ms sleep and returns `TIMEOUT` at 35 ms. A controlled timing probe reproduces that overrun without any oversleep on the retry itself. Use an absolute deadline and recompute the remaining duration from elapsed time before sleeping again. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:55 UTC · original
On crates/victory-gpu/src/frame.rs line 163 (outdated):

@@ -147,8 +147,26 @@ pub(crate) extern "system" fn wait(
         TIMEOUT
     } else {
         std::thread::sleep(wait);
-        last(kind).fetch_max(tick, Ordering::Relaxed);
-        S_OK
+        // The tick is this waiter's only when it advanced `last`: two waits
+        // that wake together otherwise both end on it. A loser waits again,
+        // on the next tick, against its original time-out.
+        let claimed = last(kind).fetch_max(tick, Ordering::Relaxed) < tick;
+        if claimed {
+            S_OK
+        } else if limit > wait {
+            let left = limit - wait;
+            let (tick, wait) = next_tick(kind);
+            if wait > left {
+                std::thread::sleep(left);
+                TIMEOUT
+            } else {
+                std::thread::sleep(wait);

P2 Badge Account for retry sleeps in pacing diagnostics

In the Windows diagnostics path, a losing waiter executes this additional sleep, but the later C::PaceUs update still uses only the outer wait.min(limit). Consequently, two simultaneous waits that sleep for approximately three intervals are reported as sleeping for only two in copystat's per-frame summary, hiding the added pacing cost from performance measurements. Accumulate the retry sleep, including the retry-timeout branch, in the reported total.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:55 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#discussion_r4688247866) On `crates/victory-gpu/src/frame.rs` line 163 (outdated): ```diff @@ -147,8 +147,26 @@ pub(crate) extern "system" fn wait( TIMEOUT } else { std::thread::sleep(wait); - last(kind).fetch_max(tick, Ordering::Relaxed); - S_OK + // The tick is this waiter's only when it advanced `last`: two waits + // that wake together otherwise both end on it. A loser waits again, + // on the next tick, against its original time-out. + let claimed = last(kind).fetch_max(tick, Ordering::Relaxed) < tick; + if claimed { + S_OK + } else if limit > wait { + let left = limit - wait; + let (tick, wait) = next_tick(kind); + if wait > left { + std::thread::sleep(left); + TIMEOUT + } else { + std::thread::sleep(wait); ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Account for retry sleeps in pacing diagnostics** In the Windows `diagnostics` path, a losing waiter executes this additional sleep, but the later `C::PaceUs` update still uses only the outer `wait.min(limit)`. Consequently, two simultaneous waits that sleep for approximately three intervals are reported as sleeping for only two in `copystat`'s per-frame summary, hiding the added pacing cost from performance measurements. Accumulate the retry sleep, including the retry-timeout branch, in the reported total. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:55 UTC · original
On crates/victory-gpu/src/frame.rs line 285 (outdated):

@@ -242,5 +260,28 @@ mod tests {
         // Even when a flip wait begins on the tick another just ended on.
         let (tick, _) = next_tick(FLIP);
         assert!(tick > flips[3]);
+
+        // Two waits that wake together take two ticks: one does not end on
+        // the tick another has claimed, both succeed.
+        assert_eq!(set_interval(null, null, 10_000, 2, 0), S_OK);
+        let _ = wait(null, 0, 0, std::ptr::null(), TOKEN_ON_TIMEOUT, &mut token);
+        let results: Vec<HRESULT> = std::thread::scope(|s| {
+            // `wait` does not dereference `this`; each thread builds its own
+            // null (a raw pointer does not cross a closure capture's Send).
+            let joins: Vec<_> = (0..2)
+                .map(|_| {
+                    s.spawn(|| {
+                        let this: This = std::ptr::null();
+                        let mut token = 0;
+                        wait(this, FLIP, u32::MAX, std::ptr::null(), 0, &mut token)
+                    })
+                })
+                .collect();
+            joins.into_iter().map(|j| j.join().unwrap()).collect()
+        });
+        assert_eq!(results, [S_OK; 2]);
+        let end = LAST[2].load(Ordering::Relaxed);
+        let (next, _) = next_tick(FLIP);
+        assert_eq!(next, end + 1, "both waits took their own tick");

P2 Badge Assert that the concurrent waits actually consume two ticks

When both waits incorrectly finish on a single tick, end is simply that tick, and next_tick(FLIP) can still return end + 1 because it schedules after LAST[2]. This assertion therefore does not establish that the waits claimed distinct ticks; running the added test block against the pre-change wait implementation still passes. Synchronize the starts and observe the claimed ticks or their progression so the regression test rejects the original race.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:55 UTC · [original](https://github.com/fxceless/victory-fork/pull/357#discussion_r4688247873) On `crates/victory-gpu/src/frame.rs` line 285 (outdated): ```diff @@ -242,5 +260,28 @@ mod tests { // Even when a flip wait begins on the tick another just ended on. let (tick, _) = next_tick(FLIP); assert!(tick > flips[3]); + + // Two waits that wake together take two ticks: one does not end on + // the tick another has claimed, both succeed. + assert_eq!(set_interval(null, null, 10_000, 2, 0), S_OK); + let _ = wait(null, 0, 0, std::ptr::null(), TOKEN_ON_TIMEOUT, &mut token); + let results: Vec<HRESULT> = std::thread::scope(|s| { + // `wait` does not dereference `this`; each thread builds its own + // null (a raw pointer does not cross a closure capture's Send). + let joins: Vec<_> = (0..2) + .map(|_| { + s.spawn(|| { + let this: This = std::ptr::null(); + let mut token = 0; + wait(this, FLIP, u32::MAX, std::ptr::null(), 0, &mut token) + }) + }) + .collect(); + joins.into_iter().map(|j| j.join().unwrap()).collect() + }); + assert_eq!(results, [S_OK; 2]); + let end = LAST[2].load(Ordering::Relaxed); + let (next, _) = next_tick(FLIP); + assert_eq!(next, end + 1, "both waits took their own tick"); ``` **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Assert that the concurrent waits actually consume two ticks** When both waits incorrectly finish on a single tick, `end` is simply that tick, and `next_tick(FLIP)` can still return `end + 1` because it schedules after `LAST[2]`. This assertion therefore does not establish that the waits claimed distinct ticks; running the added test block against the pre-change `wait` implementation still passes. Synchronize the starts and observe the claimed ticks or their progression so the regression test rejects the original race. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.