fix(agc): reserve the shader preparation thread stacks on Windows instead of committing them #6598

Merged
zaryabzip merged 2 commits from upstream-pr/6598 into main 2026-10-20 14:23:09 +00:00
zaryabzip commented 2026-10-15 22:17:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-15T22:17:47Z.


What

RegistrationPreparePool creates its threads with a 64 MiB stack through pthread_attr_setstacksize. With winpthreads that size reaches _beginthreadex without STACK_SIZE_PARAM_IS_A_RESERVATION, and then _beginthreadex uses it as the commit size: "if this flag isn't specified, stack_size specifies the commit size". Committed stack pages "remove pages from the system total commit limit" (Thread Stack Size). So every pool thread takes 64 MiB of commit before it prepares anything.

There are hardware_concurrency() / 2 preparation threads plus one library prebuild thread: 9 threads and 576 MiB on a 16-thread CPU.

On Windows the pool threads are now created with _beginthreadex(..., StackBytes, ..., STACK_SIZE_PARAM_IS_A_RESERVATION, ...):

  • The 64 MiB reservation stays, so the recursion depth is unchanged.
  • The initial commit comes from the executable's header (SizeOfStackCommit, 2 MiB in a relinked app.exe), and further pages are committed as the stack grows.
  • The pool runs host code built by GCC, which probes its stack, so growing on demand is safe there.
  • Guest threads (libkernel scePthreadCreate) are unchanged.
  • Linux and macOS keep the pthread_attr_setstacksize path.

Tested

Windows 11 (26200), i7-11800H, 16 GB RAM, NVIDIA GeForce RTX 3060 Laptop GPU (driver 617.42), WinLibs GCC 15.2.0, Release, main 5d9dcc42d.

  • New test agc_driver_registration_prepare_stack (tests/execution/RegistrationPrepareStack.cpp):
    • It measures the stack of a registration preparation thread and of the library prebuild thread from inside a task.

    • Everywhere: the task runs off the caller's thread, with at least 64 MiB reserved.

    • On Windows: at most 8 MiB committed.

    • With main's ShaderRegistry.cpp it fails:

      registration prepare stack: registration preparation thread commits 64 MiB of its 64 MiB stack up front
      
    • With this change it passes.

  • Related tests pass: agc_driver_registration_prepare_shutdown, agc_driver_prepared_shaders (all 9 variants), agc_driver_prepared_publication and agc_driver_preparation_scope_settle, 13 of 13.
  • Checks: tools/check_conventions.py passes. tools/pr_overlap.py --branch reports no conflicting PR. #1896, #5115 and #5431 could not be compared automatically; their diffs do not touch the pool's thread creation.
  • MARVEL Cosmic Invasion (PPSA29629, 02.002.000) (#5557). Each run was in a job object with a 7 GiB per-process commit cap, standing in for a machine with less free commit; 30 s per run; 3 runs each way, alternated.
    • Thread stacks at 5 s, read from each thread's TEB and VirtualQueryEx:
      • main: 7 pool threads × 64 MiB committed = 448 MiB.
      • This PR: 7 × 2 MiB = 14 MiB.
      • The 12-thread job gives 6 + 1 pool threads.
    • main: all 3 runs reach the 7.00 GiB cap.
      • One ends at 12.0 s:

        what():  replace guest placeholder with resident direct memory: The paging file is too small for this operation to complete
        
      • One ends at 8.5 s with std::bad_alloc in libSceAgcDriver.prx.

      • One stays at the cap until the time limit.

      • Process commit at 5 s: 5,888 and 5,942 MiB (3,111 MiB in the slower first run).

    • This PR: peak commit 6.57, 6.64 and 6.59 GiB. All 3 runs last the 30 s; process commit at 5 s is 5,455 to 5,479 MiB.
  • 3DMiniGolf (PPSA03647) (#2431), on main 34454bd83 with the same change: the commit plateau at the main menu falls from 6.89 to 6.45 GiB.
  • Not tested on Linux or macOS, whose code path is unchanged.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3060 Laptop GPU, driver 617.42, Windows 11 26200
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4880573326 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6598). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-15T22:17:47Z. --- ### What `RegistrationPreparePool` creates its threads with a 64 MiB stack through `pthread_attr_setstacksize`. With winpthreads that size reaches `_beginthreadex` without `STACK_SIZE_PARAM_IS_A_RESERVATION`, and then [`_beginthreadex`](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/beginthread-beginthreadex) uses it as the commit size: "if this flag isn't specified, *stack_size* specifies the commit size". Committed stack pages "remove pages from the system total commit limit" ([Thread Stack Size](https://learn.microsoft.com/en-us/windows/win32/procthread/thread-stack-size)). So every pool thread takes 64 MiB of commit before it prepares anything. There are `hardware_concurrency() / 2` preparation threads plus one library prebuild thread: 9 threads and 576 MiB on a 16-thread CPU. On Windows the pool threads are now created with `_beginthreadex(..., StackBytes, ..., STACK_SIZE_PARAM_IS_A_RESERVATION, ...)`: - The 64 MiB reservation stays, so the recursion depth is unchanged. - The initial commit comes from the executable's header (`SizeOfStackCommit`, 2 MiB in a relinked `app.exe`), and further pages are committed as the stack grows. - The pool runs host code built by GCC, which probes its stack, so growing on demand is safe there. - Guest threads (`libkernel` `scePthreadCreate`) are unchanged. - Linux and macOS keep the `pthread_attr_setstacksize` path. ### Tested Windows 11 (26200), i7-11800H, 16 GB RAM, NVIDIA GeForce RTX 3060 Laptop GPU (driver 617.42), WinLibs GCC 15.2.0, Release, `main` 5d9dcc42d. - **New test `agc_driver_registration_prepare_stack`** (`tests/execution/RegistrationPrepareStack.cpp`): - It measures the stack of a registration preparation thread and of the library prebuild thread from inside a task. - Everywhere: the task runs off the caller's thread, with at least 64 MiB reserved. - On Windows: at most 8 MiB committed. - With `main`'s `ShaderRegistry.cpp` it fails: ``` registration prepare stack: registration preparation thread commits 64 MiB of its 64 MiB stack up front ``` - With this change it passes. - **Related tests pass:** `agc_driver_registration_prepare_shutdown`, `agc_driver_prepared_shaders` (all 9 variants), `agc_driver_prepared_publication` and `agc_driver_preparation_scope_settle`, 13 of 13. - **Checks:** `tools/check_conventions.py` passes. `tools/pr_overlap.py --branch` reports no conflicting PR. #1896, #5115 and #5431 could not be compared automatically; their diffs do not touch the pool's thread creation. - **MARVEL Cosmic Invasion (PPSA29629, 02.002.000)** (#5557). Each run was in a job object with a 7 GiB per-process commit cap, standing in for a machine with less free commit; 30 s per run; 3 runs each way, alternated. - Thread stacks at 5 s, read from each thread's TEB and `VirtualQueryEx`: - `main`: 7 pool threads × 64 MiB committed = 448 MiB. - This PR: 7 × 2 MiB = 14 MiB. - The 12-thread job gives 6 + 1 pool threads. - **`main`:** all 3 runs reach the 7.00 GiB cap. - One ends at 12.0 s: ``` what(): replace guest placeholder with resident direct memory: The paging file is too small for this operation to complete ``` - One ends at 8.5 s with `std::bad_alloc` in `libSceAgcDriver.prx`. - One stays at the cap until the time limit. - Process commit at 5 s: 5,888 and 5,942 MiB (3,111 MiB in the slower first run). - **This PR:** peak commit 6.57, 6.64 and 6.59 GiB. All 3 runs last the 30 s; process commit at 5 s is 5,455 to 5,479 MiB. - **3DMiniGolf (PPSA03647)** (#2431), on `main` 34454bd83 with the same change: the commit plateau at the main menu falls from 6.89 to 6.45 GiB. - Not tested on Linux or macOS, whose code path is unchanged. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3060 Laptop GPU, driver 617.42, Windows 11 26200 - [x] AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-15 22:28:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T22:28:20Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5115 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 5431 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6867 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6946 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6947 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 7644 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6203579556 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6598#issuecomment-6203579556). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T22:28:20Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5115](https://www.github.com/boykopovar/AnyPS5/pull/5115) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 5431](https://www.github.com/boykopovar/AnyPS5/pull/5431) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 6188](https://www.github.com/boykopovar/AnyPS5/pull/6188) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 6867](https://www.github.com/boykopovar/AnyPS5/pull/6867) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 6947](https://www.github.com/boykopovar/AnyPS5/pull/6947) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` | | [PR 7644](https://www.github.com/boykopovar/AnyPS5/pull/7644) | `core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp` |
screamm commented 2026-10-17 12:07:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T12:07:27Z.


Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (driver 596.21), Ryzen 7 5700X (16 threads), WinLibs MinGW-w64 GCC 15.2, Release. PR head bf55d23ff merged on main 673f7406c (clean), alone and stacked with #6701 (also clean).

  • agc_driver_registration_prepare_stack, --repeat until-fail:3: 3 of 3. Negative control: with ShaderRegistry.cpp from main and the test kept, it fails with registration prepare stack: registration preparation thread commits 64 MiB of its 64 MiB stack up front; restored, it passes.
  • Full build and libs pass on the stack. 25 related tests (write watch, registration preparation, all agc_driver_prepared_*, host import, untracked hints; serial) pass. Non-GPU suite (878 tests): 874 pass, 2 skipped; hardware_oracle_compare timed out under load and guest_memory failed once under -j8 (0xc0000409, a libkernel test that does not load the driver); both pass serially. tools/check_conventions.py and git diff --check pass.
  • Commit charge: 3 runs of 65 s per build (main, this PR, #6701, both; interleaved), no input, no stop line in any run. Private bytes (PrivateUsage, cross-checked with Get-Process) and working set every 5 s; pool stacks counted at 35 s from each thread's TEB and VirtualQueryEx. Medians, MiB:
PS5 OpenGL Showcase PPSA99005 private 10 s 30 s 60 s WS 30 s 64 MiB-reserve stacks
main 3628 3717 3848 1454 9, 576.0 MiB committed
this PR 3028 3232 3358 1455 9, 18.1 MiB committed
#6701 3446 3598 3736 1271 9, 576.0 MiB
both 2868 3002 3121 1267 9, 18.1 MiB

On this 16-thread CPU the 9 pool stacks (8 preparation + 1 prebuild) commit exactly 576.0 MiB on main in every run and 18.1 MiB with the PR (the relinked app.exe has a 2 MiB SizeOfStackCommit, times 9). Process private bytes drop by 600 / 485 / 490 MiB at 10 / 30 / 60 s; the per-run values at 30 s do not overlap (main 3697 to 3850, PR 3200 to 3233). Working set does not move (+1 MiB), as expected for committed but untouched stack pages.

  • RetroArch PPSA99169 (picker, no input) never creates the pool (no 64 MiB-reserve stack in any run), so nothing changes there: picker private bytes 1181 vs 1180 MiB at 30 s.
  • With #6701: different files, clean stack, and the savings add (PPSA99005 at 30 s: -485 MiB this PR, -119 MiB #6701, -715 MiB both).
  • Not checked: Linux/macOS (unchanged path), AMD/Intel, a commit-capped machine, the full agc_driver_* GPU suite. System-wide commit was no use as a signal on this shared host (it moved by several GiB per run from other work).

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233696954 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6598#issuecomment-6233696954). Originally posted by [screamm](https://github.com/screamm) on 2026-10-17T12:07:27Z. --- Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (driver 596.21), Ryzen 7 5700X (16 threads), WinLibs MinGW-w64 GCC 15.2, Release. PR head `bf55d23ff` merged on main `673f7406c` (clean), alone and stacked with #6701 (also clean). - `agc_driver_registration_prepare_stack`, `--repeat until-fail:3`: 3 of 3. Negative control: with `ShaderRegistry.cpp` from main and the test kept, it fails with `registration prepare stack: registration preparation thread commits 64 MiB of its 64 MiB stack up front`; restored, it passes. - Full build and `libs` pass on the stack. 25 related tests (write watch, registration preparation, all `agc_driver_prepared_*`, host import, untracked hints; serial) pass. Non-GPU suite (878 tests): 874 pass, 2 skipped; `hardware_oracle_compare` timed out under load and `guest_memory` failed once under `-j8` (`0xc0000409`, a `libkernel` test that does not load the driver); both pass serially. `tools/check_conventions.py` and `git diff --check` pass. - Commit charge: 3 runs of 65 s per build (main, this PR, #6701, both; interleaved), no input, no stop line in any run. Private bytes (`PrivateUsage`, cross-checked with `Get-Process`) and working set every 5 s; pool stacks counted at 35 s from each thread's TEB and `VirtualQueryEx`. Medians, MiB: | PS5 OpenGL Showcase PPSA99005 | private 10 s | 30 s | 60 s | WS 30 s | 64 MiB-reserve stacks | |---|---:|---:|---:|---:|---| | main | 3628 | 3717 | 3848 | 1454 | 9, 576.0 MiB committed | | this PR | 3028 | 3232 | 3358 | 1455 | 9, 18.1 MiB committed | | #6701 | 3446 | 3598 | 3736 | 1271 | 9, 576.0 MiB | | both | 2868 | 3002 | 3121 | 1267 | 9, 18.1 MiB | On this 16-thread CPU the 9 pool stacks (8 preparation + 1 prebuild) commit exactly 576.0 MiB on main in every run and 18.1 MiB with the PR (the relinked `app.exe` has a 2 MiB `SizeOfStackCommit`, times 9). Process private bytes drop by 600 / 485 / 490 MiB at 10 / 30 / 60 s; the per-run values at 30 s do not overlap (main 3697 to 3850, PR 3200 to 3233). Working set does not move (+1 MiB), as expected for committed but untouched stack pages. - RetroArch PPSA99169 (picker, no input) never creates the pool (no 64 MiB-reserve stack in any run), so nothing changes there: picker private bytes 1181 vs 1180 MiB at 30 s. - With #6701: different files, clean stack, and the savings add (PPSA99005 at 30 s: -485 MiB this PR, -119 MiB #6701, -715 MiB both). - Not checked: Linux/macOS (unchanged path), AMD/Intel, a commit-capped machine, the full `agc_driver_*` GPU suite. System-wide commit was no use as a signal on this shared host (it moved by several GiB per run from other work). Written with Claude Code assistance (validation by a subagent, reviewed in this session).
savvaniss commented 2026-10-17 13:10:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-17T13:10:18Z.


Intel and AMD Windows data: the new test passes on both GPUs with this change and fails on both without it.

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, with VkCache emptied first. "Without" means this PR's test files on main c9e6c45de, with none of its other changes.

UHD 770 RX 9070 XT
This head bf55d23ff merged into main c9e6c45de: agc_driver_registration_prepare_stack, ×3 pass pass
Without, ×3 fails: registration preparation thread commits 64 MiB of its 64 MiB stack up front fails, same

Full CTest (--parallel 4) on main c9e6c45de with seven open GPU PRs merged (#6258, #6657, #6324, #6246, #6174, #6360, #6598): UHD 770 1381 of 1389, RX 9070 XT 1383 of 1389. main alone passes 1378 of 1385 and 1381 of 1385. The merge adds only two failures: agc_buffer_pool (#6174, both GPUs) and agc_driver_indirect_dispatch_limit (#6360, RX 9070 XT).

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6234270767 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6598#issuecomment-6234270767). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-17T13:10:18Z. --- Intel and AMD Windows data: the new test passes on both GPUs with this change and fails on both without it. Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, `ANYPS5_NO_SHADER_CACHE=1`, serial CTest. Intel UHD Graphics 770 (`8086:a780`), driver 32.0.101.7088. AMD Radeon RX 9070 XT (`1002:7550`), driver 32.0.31041.1004, with `VkCache` emptied first. "Without" means this PR's test files on `main` `c9e6c45de`, with none of its other changes. | | UHD 770 | RX 9070 XT | |---|---|---| | This head `bf55d23ff` merged into `main` `c9e6c45de`: `agc_driver_registration_prepare_stack`, ×3 | pass | pass | | Without, ×3 | fails: `registration preparation thread commits 64 MiB of its 64 MiB stack up front` | fails, same | Full CTest (`--parallel 4`) on `main` `c9e6c45de` with seven open GPU PRs merged (#6258, #6657, #6324, #6246, #6174, #6360, #6598): UHD 770 1381 of 1389, RX 9070 XT 1383 of 1389. `main` alone passes 1378 of 1385 and 1381 of 1385. The merge adds only two failures: `agc_buffer_pool` (#6174, both GPUs) and `agc_driver_indirect_dispatch_limit` (#6360, RX 9070 XT). AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-19 06:36:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T06:36:09Z.

Review: CHANGES_REQUESTED


Thanks for the measurements; the commit-vs-reserve diagnosis looks right and the new test pins it on Windows. One bug in the Windows branch of the RegistrationPreparePool constructor:

  • ShaderRegistry.cpp:1187-1194: the _beginthreadex path only does ++threads. The pthread_create path also does workers.push_back(thread) and liveWorkers.fetch_add(1). On Windows that means:
    • Close() (l.1170-1178) joins only what is in workers, so it waits for no pool thread; they can still be running Main while the pool or process tears down.
    • Main still does liveWorkers.fetch_sub(1) (l.1227) on exit, but nothing incremented it, so the unsigned counter underflows and LiveWorkers() (l.1101) returns a huge value.
  • Fix: keep the thread handle instead of closing it right after creation (WaitForSingleObject + CloseHandle in Close(), skipping the calling thread) and do liveWorkers.fetch_add(1) on success like the other path. Please also assert in the test (or in agc_driver_registration_prepare_shutdown) that LiveWorkers() is 0 after CloseAll(), so Windows CI covers it.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5567723925 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6598#pullrequestreview-5567723925). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T06:36:09Z. **Review:** CHANGES_REQUESTED --- Thanks for the measurements; the commit-vs-reserve diagnosis looks right and the new test pins it on Windows. One bug in the Windows branch of the `RegistrationPreparePool` constructor: - `ShaderRegistry.cpp:1187-1194`: the `_beginthreadex` path only does `++threads`. The `pthread_create` path also does `workers.push_back(thread)` and `liveWorkers.fetch_add(1)`. On Windows that means: - `Close()` (l.1170-1178) joins only what is in `workers`, so it waits for no pool thread; they can still be running `Main` while the pool or process tears down. - `Main` still does `liveWorkers.fetch_sub(1)` (l.1227) on exit, but nothing incremented it, so the `unsigned` counter underflows and `LiveWorkers()` (l.1101) returns a huge value. - Fix: keep the thread handle instead of closing it right after creation (`WaitForSingleObject` + `CloseHandle` in `Close()`, skipping the calling thread) and do `liveWorkers.fetch_add(1)` on success like the other path. Please also assert in the test (or in `agc_driver_registration_prepare_shutdown`) that `LiveWorkers()` is 0 after `CloseAll()`, so Windows CI covers it.
zaryabzip commented 2026-10-19 21:57:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-10-19T21:57:23Z.


Fixed in afcfe2d9e, rebased on main a70080967.

  • The Windows branch keeps each thread handle and id in workers and raises liveWorkers when it creates a thread. Close() waits for each handle (not the calling thread) and closes it.
  • agc_driver_registration_prepare_stack now requires RegistrationPreparationThreads() to equal the threads both pools started, and 0 after CloseRegistrationPreparation().

Tested: the pool class alone on macOS under ThreadSanitizer (POSIX path, 5 runs), and the Windows path cross-compiled with MinGW-w64 GCC 16.2 (compiles and links, no warnings). Not yet run on Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6278283641 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6598#issuecomment-6278283641). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-10-19T21:57:23Z. --- Fixed in `afcfe2d9e`, rebased on `main` `a70080967`. - The Windows branch keeps each thread handle and id in `workers` and raises `liveWorkers` when it creates a thread. `Close()` waits for each handle (not the calling thread) and closes it. - `agc_driver_registration_prepare_stack` now requires `RegistrationPreparationThreads()` to equal the threads both pools started, and 0 after `CloseRegistrationPreparation()`. Tested: the pool class alone on macOS under ThreadSanitizer (POSIX path, 5 runs), and the Windows path cross-compiled with MinGW-w64 GCC 16.2 (compiles and links, no warnings). Not yet run on Windows.
adriadam10 commented 2026-10-20 14:26:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T14:26:34Z.


Checked the Windows branch of RegistrationPreparePool: handles and ids are kept in workers, liveWorkers is raised on creation, Close() waits for each handle (skipping the calling thread) and closes it, and the test pins the live count against the started threads and 0 after close; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6293189234 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6598#issuecomment-6293189234). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T14:26:34Z. --- Checked the Windows branch of `RegistrationPreparePool`: handles and ids are kept in `workers`, `liveWorkers` is raised on creation, `Close()` waits for each handle (skipping the calling thread) and closes it, and the test pins the live count against the started threads and 0 after close; merged.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!6598
No description provided.