frame_pacer: wake blocked waiters on set_uncapped and guard shutdown entry #1042

Open
github-bot wants to merge 4 commits from github-bot/gh-1042 into main AGit
Owner

@⁠madhyn on GitHub · 2026-11-24 17:07 UTC · original
madhyn:fix/frame-pacer-shutdown-wakeup → main · +152 −9 · 2 files · 4 commits · open

What and why

Addresses the runtime/src/frame_pacer.h wakeup/shutdown races reported in #14 by @⁠akimfomin:

  • Mode switch wakeup (set_uncapped): set_uncapped(bool) updated uncapped_ under mutex_ without notifying cv_, so a waiter already blocked on the vblank grid missed the mode switch. It now calls cv_.notify_all() after releasing mutex_.
  • Shutdown race (~FramePacer / wait_frame_event): ~FramePacer() now holds mutex_ across setting shutdown_ = true, calling cv_.notify_all(), and entering cv_.wait(lock, ...) (eliminating the unlocked window between shutdown_ = true and cv_.wait), and wait_frame_event returns pacer_hr::invalid_state immediately if shutdown_ is already set before incrementing waiters_.

Testing

  • Added regression tests in runtime/test/frame_pacer_test.cpp covering:
    • Destroying FramePacer with multiple blocked waiters (origin, vblank, flip).
    • Calling set_uncapped(true) while a waiter is blocked on ManualFrameClock.
  • ctest -R frame_pacer --output-on-failure (Wine 11.22, clang-cl + xwin): 1/1 passed (6.69 s).

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 17:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042) `madhyn:fix/frame-pacer-shutdown-wakeup` → `main` · +152 −9 · 2 files · 4 commits · open ### What and why Addresses the `runtime/src/frame_pacer.h` wakeup/shutdown races reported in #14 by @⁠akimfomin: - **Mode switch wakeup (`set_uncapped`):** `set_uncapped(bool)` updated `uncapped_` under `mutex_` without notifying `cv_`, so a waiter already blocked on the vblank grid missed the mode switch. It now calls `cv_.notify_all()` after releasing `mutex_`. - **Shutdown race (`~FramePacer` / `wait_frame_event`):** `~FramePacer()` now holds `mutex_` across setting `shutdown_ = true`, calling `cv_.notify_all()`, and entering `cv_.wait(lock, ...)` (eliminating the unlocked window between `shutdown_ = true` and `cv_.wait`), and `wait_frame_event` returns `pacer_hr::invalid_state` immediately if `shutdown_` is already set before incrementing `waiters_`. ### Testing - Added regression tests in `runtime/test/frame_pacer_test.cpp` covering: - Destroying `FramePacer` with multiple blocked waiters (`origin`, `vblank`, `flip`). - Calling `set_uncapped(true)` while a waiter is blocked on `ManualFrameClock`. - `ctest -R frame_pacer --output-on-failure` (Wine 11.22, `clang-cl` + `xwin`): **1/1 passed** (6.69 s). AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:34:53 +00:00
Author
Owner

@⁠morodirule on GitHub · 2026-11-24 17:08 UTC · original

Independent Linux check (native g++, ManualFrameClock, no game/GPU): my earlier finding repro now passes on head 5496f79f9 — flipping set_uncapped(true) wakes a tick-blocked waiter with rc=0 (was stuck till timeout), shutdown with a blocked waiter still 0 ms. Full frame_pacer_test: all cases pass, exit 0. The new uncapped-wakeup test in the PR covers the fixed path. This confirms the finding I reported on #14. Not claiming; review evidence.

**@⁠morodirule** on GitHub · 2026-11-24 17:08 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7138758788) Independent Linux check (native g++, ManualFrameClock, no game/GPU): my earlier finding repro now passes on head 5496f79f9 — flipping set_uncapped(true) wakes a tick-blocked waiter with rc=0 (was stuck till timeout), shutdown with a blocked waiter still 0 ms. Full frame_pacer_test: all cases pass, exit 0. The new uncapped-wakeup test in the PR covers the fixed path. This confirms the finding I reported on #14. Not claiming; review evidence.
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 17:20 UTC · original · approved these changes

Verified on exact head 5496f79f93c41f1134ce4c9e1d2674aa00c6bb55. I built runtime/test/frame_pacer_test.cpp on Linux with GCC 16.2 (-std=c++20 -pthread) and ran it successfully: frame_pacer_test: all cases pass, including blocked waiter release on set_uncapped(true) and destruction with three waiters. Changed-file no-game-data and git diff --check pass; merge-tree onto current main is clean. This independently validates the new threading regressions on Linux in addition to the PR-reported Windows/Wine run.

**@⁠KernelSmoker** on GitHub · 2026-11-24 17:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#pullrequestreview-6044064503) · **approved these changes** Verified on exact head 5496f79f93c41f1134ce4c9e1d2674aa00c6bb55. I built `runtime/test/frame_pacer_test.cpp` on Linux with GCC 16.2 (`-std=c++20 -pthread`) and ran it successfully: `frame_pacer_test: all cases pass`, including blocked waiter release on `set_uncapped(true)` and destruction with three waiters. Changed-file no-game-data and `git diff --check` pass; merge-tree onto current main is clean. This independently validates the new threading regressions on Linux in addition to the PR-reported Windows/Wine run.
Author
Owner

@⁠akimfomin on GitHub · 2026-11-24 17:21 UTC · original

Native Windows CPU check for 5496f79f93c41f1134ce4c9e1d2674aa00c6bb55 (Windows 11 build 28000, LLVM-MinGW Clang 23.1.6, C++20). The registered frame_pacer CTest passed 3/3 (1.19–1.20 s).

As a control, I used the unchanged PR tests with the header from the PR commit's parent fce586c6. All three runs failed the two-second uncapped-wakeup assertion before the six-second process timeout. The parent’s original suite and the new shutdown test in isolation each passed 3/3 on the parent header. This A/B reproduced the missed wakeup.

PortBridge linked the original Reforge tests to this Continued finding (PB-0020). Synthetic CPU target, runtime disabled, no game files or GPU. AI-assisted.

**@⁠akimfomin** on GitHub · 2026-11-24 17:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7139082325) Native Windows CPU check for `5496f79f93c41f1134ce4c9e1d2674aa00c6bb55` (Windows 11 build 28000, LLVM-MinGW Clang 23.1.6, C++20). The registered `frame_pacer` CTest passed 3/3 (1.19–1.20 s). As a control, I used the unchanged PR tests with the header from the PR commit's parent `fce586c6`. All three runs failed the two-second uncapped-wakeup assertion before the six-second process timeout. The parent’s original suite and the new shutdown test in isolation each passed 3/3 on the parent header. This A/B reproduced the missed wakeup. [PortBridge](https://github.com/akimfomin/PortBridge) linked the original Reforge tests to this Continued finding ([PB-0020](https://akimfomin.github.io/PortBridge/cases/pb-0020.html)). Synthetic CPU target, runtime disabled, no game files or GPU. AI-assisted.
Author
Owner

@⁠fin-github on GitHub · 2026-11-24 18:00 UTC · original · reviewed

Built frame_pacer_test standalone with cl /std:c++20 /W4 /permissive- /utf-8 /O2:

  • PR head: frame_pacer_test: all cases pass, 5 of 5 runs.
  • main (32950551e) header with this PR's test file: fails at line 661 (waiter.wait_for(2 s) == ready), so the
    set_uncapped case catches the missed wakeup.

One gap: the new destructor case also passes with main's header, so nothing tests the shutdown half of the change
(setting shutdown_ under the same lock as the wait, and the early invalid_state return in wait_frame_event).
Could you add a case for a waiter that arrives after shutdown has started? For example, hold the pacer in
~FramePacer's cv_.wait with one blocked waiter, then call wait_frame_event from another thread and expect
invalid_state with no hang. Without that case, a later edit could undo the guard without failing anything.

Tested on Windows 11 Pro 26200, CPython 3.14.4, MSVC from VS 18 Community, applied on main 32950551e. No GPU or game files used. AI-assisted (Claude Code).

**@⁠fin-github** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#pullrequestreview-6044649650) · **reviewed** Built `frame_pacer_test` standalone with `cl /std:c++20 /W4 /permissive- /utf-8 /O2`: - PR head: `frame_pacer_test: all cases pass`, 5 of 5 runs. - `main` (32950551e) header with this PR's test file: fails at line 661 (`waiter.wait_for(2 s) == ready`), so the `set_uncapped` case catches the missed wakeup. One gap: the new destructor case also passes with `main`'s header, so nothing tests the shutdown half of the change (setting `shutdown_` under the same lock as the wait, and the early `invalid_state` return in `wait_frame_event`). Could you add a case for a waiter that arrives after shutdown has started? For example, hold the pacer in `~FramePacer`'s `cv_.wait` with one blocked waiter, then call `wait_frame_event` from another thread and expect `invalid_state` with no hang. Without that case, a later edit could undo the guard without failing anything. Tested on Windows 11 Pro 26200, CPython 3.14.4, MSVC from VS 18 Community, applied on main 32950551e. No GPU or game files used. AI-assisted (Claude Code).
Author
Owner

@⁠akimfomin on GitHub · 2026-11-24 18:06 UTC · original

Follow-up to fin-github’s Windows review: a check of the return code alone passes before and after the guard. I tried a live-object test seam that sets shutdown_ under the pacer’s mutex, plus a counting FrameClock. The active control succeeds and returns a token before stopping. After stopping, a separate thread calls wait_frame_event while the object remains alive.

Across five runs per variant, exact head 5496f79f, that head with only the early guard removed, and parent fce586c6 all returned invalid_state with a zero token. The exact head made zero late clock reads. Removing the guard or using the parent made one late clock read in every run, because the call reached wait_locked before its shutdown check.

This gives a deterministic regression for rejecting new work before entering the wait path. The scope is the early gate on a live object. Windows 11 build 28000, LLVM-MinGW Clang 23.1.6, CPU only. PortBridge linked the review to the prior Windows A/B. AI-assisted.

**@⁠akimfomin** on GitHub · 2026-11-24 18:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7140165184) Follow-up to [fin-github’s Windows review](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1042): a check of the return code alone passes before and after the guard. I tried a live-object test seam that sets `shutdown_` under the pacer’s mutex, plus a counting `FrameClock`. The active control succeeds and returns a token before stopping. After stopping, a separate thread calls `wait_frame_event` while the object remains alive. Across five runs per variant, exact head `5496f79f`, that head with only the early guard removed, and parent `fce586c6` all returned `invalid_state` with a zero token. The exact head made **zero** late clock reads. Removing the guard or using the parent made **one** late clock read in every run, because the call reached `wait_locked` before its shutdown check. This gives a deterministic regression for rejecting new work before entering the wait path. The scope is the early gate on a live object. Windows 11 build 28000, LLVM-MinGW Clang 23.1.6, CPU only. [PortBridge](https://github.com/akimfomin/PortBridge) linked the review to the prior Windows A/B. AI-assisted.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 18:11 UTC · original

Added the late-waiter-during-shutdown regression test in runtime/test/frame_pacer_test.cpp (thank you @⁠fin-github and @⁠akimfomin for the review and A/B clock-read suggestion):

  • HoldingClock holds the first waiter out of returning while ~FramePacer() is parked in cv_.wait(lock, waiters_ == 0), then a second thread calls wait_frame_event while shutdown is in progress.
  • Verifies it returns pacer_hr::invalid_state with token == 0, no hang, and zero additional now_us() clock reads (proving the early if (shutdown_) gate in wait_frame_event rejects before entering wait_locked).
  • ctest -R frame_pacer --output-on-failure (Wine 11.22, clang-cl + xwin): 1/1 passed (1.69 s).

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 18:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7140296627) Added the late-waiter-during-shutdown regression test in `runtime/test/frame_pacer_test.cpp` (thank you @⁠fin-github and @⁠akimfomin for the review and A/B clock-read suggestion): - `HoldingClock` holds the first waiter out of returning while `~FramePacer()` is parked in `cv_.wait(lock, waiters_ == 0)`, then a second thread calls `wait_frame_event` while shutdown is in progress. - Verifies it returns `pacer_hr::invalid_state` with `token == 0`, no hang, and **zero** additional `now_us()` clock reads (proving the early `if (shutdown_)` gate in `wait_frame_event` rejects before entering `wait_locked`). - `ctest -R frame_pacer --output-on-failure` (Wine 11.22, `clang-cl` + `xwin`): **1/1 passed** (1.69 s). AI-assisted: yes
Author
Owner

@⁠akimfomin on GitHub · 2026-11-24 18:19 UTC · original

Thanks for adding the clock check. I ran the registered test source at exact head 79a8f595 on native Windows with LLVM-MinGW Clang 23.1.6, CPU only. It passed 5/5. Removing only the early shutdown guard made the clock assertion print in 5/5 runs, but each process then hung until the 6.5 s watchdog. The failing EXPECT returns before the still-blocked waiter is released, so cleanup waits on a future.

A test-only change fixed that failure path locally. Save const int reads_after_late = clock.now_calls.load(); immediately after late.get() and before releasing the clock. Move the late result assertion and the comparison of reads_after_late to reads_before_late to just after dtor.get(). The snapshot still measures the late caller. With that change the stock guard passed 5/5, and the guard-off control exited with the clock assertion and code 1 in 5/5 runs (~1.3 s). The production header is unchanged in the candidate. PortBridge case PB-0020. AI-assisted.

**@⁠akimfomin** on GitHub · 2026-11-24 18:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7140485965) Thanks for adding the clock check. I ran the registered test source at exact head `79a8f595` on native Windows with LLVM-MinGW Clang 23.1.6, CPU only. It passed 5/5. Removing only the early shutdown guard made the clock assertion print in 5/5 runs, but each process then hung until the 6.5 s watchdog. The failing `EXPECT` returns before the still-blocked waiter is released, so cleanup waits on a future. A test-only change fixed that failure path locally. Save `const int reads_after_late = clock.now_calls.load();` immediately after `late.get()` and before releasing the clock. Move the late result assertion and the comparison of `reads_after_late` to `reads_before_late` to just after `dtor.get()`. The snapshot still measures the late caller. With that change the stock guard passed 5/5, and the guard-off control exited with the clock assertion and code 1 in 5/5 runs (~1.3 s). The production header is unchanged in the candidate. [PortBridge case PB-0020](https://akimfomin.github.io/PortBridge/#/problems/PB-0020). AI-assisted.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 18:30 UTC · original

Updated runtime/test/frame_pacer_test.cpp per @⁠akimfomin's note: snapshot reads_after_late right after late.get(), release HoldingClock and join dtor/first before checking the late-waiter EXPECT assertions so even a regression failure exits cleanly without blocking on cleanup.

ctest -R frame_pacer --output-on-failure (Wine 11.22, clang-cl + xwin): 1/1 passed (1.8 s).

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 18:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7140737395) Updated `runtime/test/frame_pacer_test.cpp` per @⁠akimfomin's note: snapshot `reads_after_late` right after `late.get()`, release `HoldingClock` and join `dtor`/`first` before checking the late-waiter `EXPECT` assertions so even a regression failure exits cleanly without blocking on cleanup. `ctest -R frame_pacer --output-on-failure` (Wine 11.22, `clang-cl` + `xwin`): **1/1 passed** (1.8 s). AI-assisted: yes
Author
Owner

@⁠akimfomin on GitHub · 2026-11-24 19:49 UTC · original

Follow-up to the separate waiter-accounting check in the PortBridge pilot. On exact 0b65330e, the ordinary control completed 3/3 on Windows. When a synthetic clock threw from now_us() or wait() while the pacer mutex was held, the exception propagated and a later ordinary wait succeeded. Teardown then stopped in both runs of each exception case. A 2 s watchdog stopped those isolated test processes.

A local change releases the registration as it goes out of scope, before the mutex unlocks. I tested this replacement after ++waiters_ in wait_frame_event:

struct WaiterRegistration {
    std::uint32_t& count;
    std::condition_variable& cv;
    ~WaiterRegistration() {
        if (--count == 0) cv.notify_all();
    }
} waiter{waiters_, cv_};
return wait_locked(lock, event, timeout_ms, flags, token);

The candidate finished all 9 ordinary and exception checks and all 10 shutdown checks where an existing waiter threw with shutdown underway. The registered frame_pacer_test passed 3/3 on each version. The candidate documents that an injected clock must retain or reacquire the same mutex before it returns or throws. The controls use that contract. This is a separate candidate for review on the public Continued code. PortBridge PB-0020. AI-assisted.

**@⁠akimfomin** on GitHub · 2026-11-24 19:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7142646056) Follow-up to the separate waiter-accounting check in [the PortBridge pilot](https://github.com/akimfomin/PortBridge/issues/41#issuecomment-7142175216). On exact `0b65330e`, the ordinary control completed 3/3 on Windows. When a synthetic clock threw from `now_us()` or `wait()` while the pacer mutex was held, the exception propagated and a later ordinary wait succeeded. Teardown then stopped in both runs of each exception case. A 2 s watchdog stopped those isolated test processes. A local change releases the registration as it goes out of scope, before the mutex unlocks. I tested this replacement after `++waiters_` in `wait_frame_event`: ```cpp struct WaiterRegistration { std::uint32_t& count; std::condition_variable& cv; ~WaiterRegistration() { if (--count == 0) cv.notify_all(); } } waiter{waiters_, cv_}; return wait_locked(lock, event, timeout_ms, flags, token); ``` The candidate finished all 9 ordinary and exception checks and all 10 shutdown checks where an existing waiter threw with shutdown underway. The registered `frame_pacer_test` passed 3/3 on each version. The candidate documents that an injected clock must retain or reacquire the same mutex before it returns or throws. The controls use that contract. This is a separate candidate for review on the public Continued code. [PortBridge PB-0020](https://akimfomin.github.io/PortBridge/cases/pb-0020.html). AI-assisted.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 20:24 UTC · original

Applied @⁠akimfomin's WaiterRegistration RAII guard in wait_frame_event (33195f846) so --waiters_ and cv_.notify_all() still run before lock unlocks if an injected clock throws from now_us() or wait(), and added both exception-unwind cases to runtime/test/frame_pacer_test.cpp.

Verified after the final edit:

  • ctest --test-dir runtime/build/linux -R "^frame_pacer$" --output-on-failure: 1/1 passed (1.25 s)
  • ctest --test-dir runtime/build/win -R "^frame_pacer$" --output-on-failure (Wine 11.22, clang-cl + xwin): 1/1 passed (6.56 s)

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 20:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7143506847) Applied @⁠akimfomin's `WaiterRegistration` RAII guard in `wait_frame_event` (`33195f846`) so `--waiters_` and `cv_.notify_all()` still run before `lock` unlocks if an injected clock throws from `now_us()` or `wait()`, and added both exception-unwind cases to `runtime/test/frame_pacer_test.cpp`. Verified after the final edit: - `ctest --test-dir runtime/build/linux -R "^frame_pacer$" --output-on-failure`: **1/1 passed** (1.25 s) - `ctest --test-dir runtime/build/win -R "^frame_pacer$" --output-on-failure` (Wine 11.22, `clang-cl` + `xwin`): **1/1 passed** (6.56 s) AI-assisted: yes
Author
Owner

@⁠titoreinaldo on GitHub · 2026-11-24 20:44 UTC · original

The late-waiter regression assumes the asynchronous destructor has set shutdown_ after a 50 ms sleep. If that worker is delayed, the supposedly late waiter can register while the pacer is still running, so this test can fail even with the production guard working correctly. On exact head 33195f846 with GCC 14.2 on Linux, the unchanged fixture passed 3/3. Adding a 250 ms delay before pacer.reset() in the test’s destructor lambda, with production code unchanged, made it fail 3/3 at EXPECT(late_ready). Could the fixture wait for an explicit shutdown acknowledgement rather than elapsed time, or use a live-object shutdown test seam? CPU-only; AI-assisted.

**@⁠titoreinaldo** on GitHub · 2026-11-24 20:44 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7143996140) The late-waiter regression assumes the asynchronous destructor has set `shutdown_` after a 50 ms sleep. If that worker is delayed, the supposedly late waiter can register while the pacer is still running, so this test can fail even with the production guard working correctly. On exact head `33195f846` with GCC 14.2 on Linux, the unchanged fixture passed 3/3. Adding a 250 ms delay before `pacer.reset()` in the test’s destructor lambda, with production code unchanged, made it fail 3/3 at `EXPECT(late_ready)`. Could the fixture wait for an explicit shutdown acknowledgement rather than elapsed time, or use a live-object shutdown test seam? CPU-only; AI-assisted.
Author
Owner

@⁠akimfomin on GitHub · 2026-11-24 21:04 UTC · original

I followed up on titoreinaldo’s fixture review at 33195f846. A deterministic fixture sets shutdown_ under the mutex through a private friend FramePacerTestAccess, with the pacer alive throughout the call. It uses a counting clock and a synchronous zero-timeout wait. The separate existing test still covers destruction with already registered waiters.

The essential assertions after setup(pacer, 1) are:

const int reads_before_wait = clock.now_calls;
FramePacerTestAccess::mark_shutdown(pacer);
std::uint64_t token = 27;
EXPECT(pacer.wait_frame_event(frame_event_origin, 0, 0, &token) == pacer_hr::invalid_state);
EXPECT(token == 27);
EXPECT(clock.now_calls == reads_before_wait);

The standalone registered test passed 3/3 on 33195f846 and 3/3 with the fixture on its parent 0b65330e, on Windows with LLVM-MinGW Clang 23.1.6. In the isolated control with only the early check omitted, the test reported one clock read and exited on the expected assertion in all three runs. The only header change is friend struct FramePacerTestAccess;. That helper acquires pacer.mutex_ and sets pacer.shutdown_ = true.

PortBridge connected the reviewer’s finding with the existing waiter checks in PB-0020. AI-assisted with OpenAI Codex.

**@⁠akimfomin** on GitHub · 2026-11-24 21:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7144431667) I followed up on [titoreinaldo’s fixture review](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1042) at `33195f846`. A deterministic fixture sets `shutdown_` under the mutex through a private friend `FramePacerTestAccess`, with the pacer alive throughout the call. It uses a counting clock and a synchronous zero-timeout wait. The separate existing test still covers destruction with already registered waiters. The essential assertions after `setup(pacer, 1)` are: ```cpp const int reads_before_wait = clock.now_calls; FramePacerTestAccess::mark_shutdown(pacer); std::uint64_t token = 27; EXPECT(pacer.wait_frame_event(frame_event_origin, 0, 0, &token) == pacer_hr::invalid_state); EXPECT(token == 27); EXPECT(clock.now_calls == reads_before_wait); ``` The standalone registered test passed 3/3 on `33195f846` and 3/3 with the fixture on its parent `0b65330e`, on Windows with LLVM-MinGW Clang 23.1.6. In the isolated control with only the early check omitted, the test reported one clock read and exited on the expected assertion in all three runs. The only header change is `friend struct FramePacerTestAccess;`. That helper acquires `pacer.mutex_` and sets `pacer.shutdown_ = true`. [PortBridge](https://github.com/akimfomin/PortBridge) connected the reviewer’s finding with the existing waiter checks in [PB-0020](https://akimfomin.github.io/PortBridge/cases/pb-0020.html). AI-assisted with OpenAI Codex.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 21:20 UTC · original

@⁠titoreinaldo Good catch — replaced the 50 ms sleep in runtime/test/frame_pacer_test.cpp with an explicit condition-variable signal (HoldingClock::woke_from_cv) set right after cv.wait(lock) returns in ~FramePacer(), so the late-waiter check only runs once shutdown_ is set and the teardown wakeup has fired.

Verified with frame_pacer_test (g++ -std=c++20 -O2 -pthread): frame_pacer_test: all cases pass.

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 21:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7144798685) @⁠titoreinaldo Good catch — replaced the 50 ms sleep in `runtime/test/frame_pacer_test.cpp` with an explicit condition-variable signal (`HoldingClock::woke_from_cv`) set right after `cv.wait(lock)` returns in `~FramePacer()`, so the late-waiter check only runs once `shutdown_` is set and the teardown wakeup has fired. Verified with `frame_pacer_test` (`g++ -std=c++20 -O2 -pthread`): `frame_pacer_test: all cases pass`. AI-assisted: yes
Author
Owner

@⁠madhyn on GitHub · 2026-11-25 04:52 UTC · original

Rebased onto current main (c7e82e26e), keeping the shutdown_ guard ahead of the current_origin_poll_ fast path in wait_frame_event. Re-ran frame_pacer_test on both host Linux (g++ -std=c++20) and Windows cross-build (clang-cl /W4 under Wine 11.22): all cases pass.

**@⁠madhyn** on GitHub · 2026-11-25 04:52 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1042#issuecomment-7153237147) Rebased onto current `main` (`c7e82e26e`), keeping the `shutdown_` guard ahead of the `current_origin_poll_` fast path in `wait_frame_event`. Re-ran `frame_pacer_test` on both host Linux (`g++ -std=c++20`) and Windows cross-build (`clang-cl /W4` under Wine 11.22): all cases pass.
This pull request has changes conflicting with the target branch.
  • runtime/test/frame_pacer_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1042/head:github-bot/gh-1042'
git switch 'github-bot/gh-1042'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1042'
git switch 'github-bot/gh-1042'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1042'
git switch 'github-bot/gh-1042'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1042'
git switch 'main'
git merge --squash 'github-bot/gh-1042'
git switch 'main'
git merge --ff-only 'github-bot/gh-1042'
git switch 'main'
git merge 'github-bot/gh-1042'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.